Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gravity Forms sending entry data combined from multiple forms to third-party after submitting a specific form

I am not familiar with gravity form hooks. I have created 2 sign up process forms that are displayed in a single modal but called in different divs. I wanted to send these data from 2 forms to a third party application using gform_after_submission send entry data to third-party after submitting a specific form (last form).

However doing this:

add_action( 'gform_after_submission_2', '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 ) );
}

will only allow me to get entry fields from the form id specified.

How would it be possible that I will get entries from other forms too so that I could include and post it to third party url?

Thanks ahead.

like image 299
Eleonor Somosot Avatar asked Sep 16 '15 03:09

Eleonor Somosot


People also ask

How do you pass a parameter in gravity form?

You can populate a field via the Gravity Forms shortcode by adding the field_values parameter. The field_values parameter accepts multiple dynamic population parameters separated by an ampersand (&). In this example, any fields with the dynamic population parameter parameter_name1 would be populated with value1.

How does gravity forms save data?

Within the form settings page, you should see an option labeled Save and Continue. Simply enable the checkbox to allow Save and Continue functionality within the form. Upon enabling Save and Continue, an additional field will be available to change the link text.


1 Answers

Because you are specifying the form ID in the add_action itself, you are only running your function when the Gravity Form, with an ID of 2, is submitted. If you want it to run for multiple submissions, but then limit it to specific form IDs, then something more like this:

   add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
   function post_to_third_party( $entry, $form ) {

    if( $form->id == 2 || $form->id == somenumber ) {
        $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 ) );
    }
}

You might need to use $form['id'] in the event you aren't dealing with the object. One of them will work. The downside is you must know the ID of the forms you want to work with. This is easily found in the backend when viewing the table of forms you've created, but it is what it is...

like image 150
Daniel C Avatar answered Sep 21 '22 17:09

Daniel C