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

2

7

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.

Madalinemadalyn answered 16/9, 2015 at 3:2 Comment(3)
You would need to know the entry IDs so you could fetch them via GFAPI::get_entry( $entry_id ).Impermanent
does it get the entries from other forms also?Madalinemadalyn
Yes. It will get any entry from any form if you know the entry ID.Impermanent
T
1

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

Travistravus answered 18/11, 2015 at 20:39 Comment(0)
D
0

If you are saving form data to the same post maybe you can get the date based on post id

Diplex answered 30/10, 2015 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.