Send data to third party with WordPress Gravity Forms

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?

Related posts

3 comments

  1. 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:

    add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
    function post_to_third_party( $entry, $form ) {
        if($form['title'] !== 'your-form-title'){ //Check the title
            return; //If the title doesn't match, don't POST
        }
        $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 ) );
    
    }
    

    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

Comments are closed.