I’m using the following code in functions.php to submit to a third party via cURL.
The issue is this code is universal for all my Form Instances (I have countless Gravity Forms on my WP site and I only need one to go to this 3rd party)
add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
$post_url = 'http://thirdparty.com';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'message' => rgar( $entry, '3' ),
);
$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
}
How do I select which forms to use this third party call on?
The link you posted contains nearly all of the documentation you need to know about Gravity Forms. All you need to do is check the
$form
argument for any identifiers that the current form uses:This checks the title beforehand to determine whether or not you actually want to post your information to your third party URL. While checking the title would certainly make your code more readable, I would actually recommend checking the ID of your forms for better reliability. More information on Form Objects here
You can append the form id to the action name to hook into a specific form:
The documentation for gform_after_submission can be found here.
Forms 3rd party Integration Plugin allowed me to set up multiple third party forms and fully integrated with gravity forms.