Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How do I customize this PHP Script for Gravity forms? WordPress


I am trying to send form data to a 3rd party system via a URL query string.

I am currently using Gravity forms version 1.6.2. The tech support at gravity forms suggested I use the gform_after_submission hook and create custom PHP under the form_display.php file. They referred me to this basic script below.

add_action("gform_after_submission", "set_post_content", 10, 2);
function set_post_content($entry, $form){

//getting post
$post = get_post($entry["post_id"]);

//changing post content
$post->post_content = "Blender Version:" . $entry[7] . "<br/> <img src='" . $entry[8] . "'> <br/> <br/> " . $entry[13] . " <br/> <img src='" . $entry[5] . "'>";

//updating post

My question is the following:

How do I set the URL for submission to be
Also I need to include each field ID.

Currently the post string looks something like this:

I believe Gravity forms uses form field IDs like {name:3}

Once the data is passed, I would like to read the response from the third party system which should be in an XML format and only has two values.

1) "success"
2) "reject"

Based on the success response, I would like to send the user to a thank you page of

If I get a reject response, I would like to send them to for example.

Answers (1)


John Cotton answers:

I can't promise this will work as I don't have Gravity Forms installed any more (I didn't like it very much ) and so can't test this. Also, you haven't told us what is in your form...

However, I recall that you get an array of fields from $form. Assuming that you have a form value for each query string parameter you need to send, something like this will work:

function set_post_content( $entry, $form ) {

$querystring = http_build_query( $form['fields'] );

$path = ''. $querystring;

curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 45);
$r = curl_exec($ch);

if( strstr( $r, 'success' ) ) {
$location = '';
} else {
$location = '';

header( 'Location: '.$location );
add_action( 'gform_after_submission', 'set_post_content', 10, 2 );

I've not bothered with any sophisticated processing of the XML as you seem to only need to know whether the string contains 'success' or not...

Let me know how you get on.

ksailam comments:

John - thanks for your quick reply. I agree Gravity forms needs some work. Do you suggest any other form plugins?

For the form fields, each one does have an ID. An example form screenshot is attached.

I believe this sample query string gives you the form element ids.
ckm_campaign_id=&ckm_key=&ckm_subid=&first_name={Name (First):1.3}&last_name={Name (Last):1.6}&address={address (Street Address):2.1}&address2={address (Address Line 2):2.2}&city={address (City):2.3}&state2={state2:9}&zip_code={address (Zip / Postal Code):2.5}&email_address={email_address:5}&phone={phone:23}&phone_type={phone_type:7}&phone_cell={phone_cell:24}&phone2_type={phone2_type:6}&best_time=&ip_address={ip}&opt_in={opt_in:11}&grad_year={grad_year:21}&adkey={adkey:12}&program_code={program_code:8}&military={military:15}&vendor_token={entry_id}&source_code={source_code:13}&affiliate_id={affiliate_id:16}&Express_consent={opt_in:11}&AdvSearchTerm={AdvSearchTerm:17}&lead_url={entry_url}&server_source=192.168.01&loe={loe:14}&country2={country2:22}

Let me know if this info helps.

My question on your sample would be where do I put each of the form fields to be captured and sent to the third party system?

I can send you an email to a live example if you wish.