Getting entry fields from gravity form

I am working on using Gravity Forms to submit to a third party API. I have been reading the documentation for gform_after_submission and I can’t figure out how to refer to the fields in my form when I submit the values that are in the form. I am seeing things like this:

$body = array(
    'brand' => $entry['20'],
    'product' => $entry['22'],
    'form_id' => $entry['21'],
    'title' => $entry['24'],
    'fname' => $entry['23'],
    'lname' => $entry['17'],
    'postcode' => $entry['14'],
    'address1' => $entry['2.1'],
    'address2' => $entry['2.2'],
    'town' => $entry['2.3'],
    'county' => $entry['2.4']   
    );

However, I have no idea where they get what the entry is on the Gravity form I created. I appreciate any help I can get in this.

Jerry

Hi Jerry. gform_after_submission can be applied to all forms or individual forms. When you apply it to an individual form like this:

add_action( 'gform_after_submission_93', 'send_to_api', 10, 2 );

That means when form 93 is submitted, this hooks runs, and you have an $entry you can access, like this:

add_action( 'gform_after_submission_93', 'send_to_api', 10, 2 );
function send_to_api( $entry, $form ) {
	// take what was submitted in field 21 of the entry and
	// assign it to $some_variable
	$some_variable = rgar ( $entry, '21' );
	// do something with that variable
}

I used the helper function rgar to access to $entry:

Does that make sense? Because gform_after_submission runs after every form submission (of submissions for a specific form if you limit it like I did) you will have a single $entry where you can find all the information that was submitted in the form.

Let me know if you have any other questions.

2 Likes

It does make sense. And helps a lot. Where I am stuck is how would I use the JSON file I have with those form IDs. That documentation helps but not with nested JSON. I’ve almost wanted to see if I can use the enqueue and then when the form submits I use Javascript since that is what I am more familiar with. But getting the IDs of each of the form elements to stay the same would be tricky.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.