1
votes

I'm struggling with getting remote post response data to print on the Gravity Forms confirmation page. The data from the form is posted to the 3rd party site successfully and my logs show that the response data is received, however the received data is not printing to the confirmation page.

I have tried many variations such as;

$request  = new WP_Http();
$data = json_decode( wp_remote_retrieve_body( $response ) );
$response = wp_remote_post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_confirmation: response => ' . print_r(         $response, true ) );

return $confirmation;

I submit the data via a plugin and have tried with the filters gform_confirmation, gform_after_submission, and gform_entry_post_save to no avail.

After many support tickets to Gravity Forms; I'm told that to do this requires additional scripting.

Thank you, Richard

This is the code I have so far for the plugin.

add_filter( 'gform_confirmation_2', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {

 $post_url = 'my_post_url';
 $body = array(
    'VTC_ID' => rgar( $entry, '15' ), 
    'Member_ID' => rgar( $entry, '16' ), 
    'bname' => rgar( $entry, '3' ),
    'baddress' => rgar( $entry, '4' ),
    'bcity' => rgar( $entry, '5' ),
    'bstate' => rgar( $entry, '6' ),
    'bcountry' => rgar( $entry, '7' ),
    'bzip' => rgar( $entry, '8' ),
    'phone' => rgar( $entry, '9' ),
    'email' => rgar( $entry, '17' ),
    'password' => rgar( $entry, '11' ),
    'isTrial' => rgar( $entry, '12' ),
    'isActive' => rgar( $entry, '18' ),
    'trialStart' => rgar( $entry, '13' ),
    'trialEnd' => rgar( $entry, '14' ),
    );

    GFCommon::log_debug( 'gform_confirmation: body => ' . print_r( $body, true ) );        

$request  = new WP_Http();
$response = wp_remote_post( $post_url, $parameters );
$confirmation .= print_r( $response, true );
return $confirmation;

GFCommon::log_debug( 'gform_confirmation: response => ' . print_r( $response, true ) );

}
2
question is not clear. Could you please elaborate it?Francisco R
My form sends data to a remote site. The data sent creates a user on the remote site. 1 of the fields on my form is empty which, triggers the remote site to create an account number. I'm trying to print the account number to the local site confirmation page. My Gravity Forms log shows that the response data (account number) is received by the local site, but I am not understanding how to print that data to the confirmation page.Richard

2 Answers

0
votes

Assuming everything is part of the same submission process, you should be able to use the gform_confirmation hook instead of the gform_after_submission.

add_filter( 'gform_confirmation_123', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
    $response = wp_remote_post( $post_url, $parameters );
    $confirmation .= print_r( $response, true );
    return $confirmation;
}

This assumes that:

  • Your confirmation is configured for text (not page or redirect)

You will need to:

  • Update the "123" in the filter name to your form ID
  • Update the wp_remote_post() to actually use the variables applicable to your request
  • Update the $confirmation to include the actual content from the response that you want
0
votes

Starting with @dave-from-gravity-wiz answer, I used GET not POST with github API for simplicity when experimenting

add_filter( 'gform_confirmation_4', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$response = wp_remote_get( 'https://api.github.com/users/someuser' );

if ( is_wp_error( $response ) ) {
   echo 'An error happened';
} else {
   $body = wp_remote_retrieve_body( $response );
   $data = json_decode( $body );
}

$confirmation .= print_r( $data->id, true );
return $confirmation;

}

This takes the json table you can see on the url and only prints the 'id' number in the response on the form submission confirmation, or any key label you change it to. If you want to show more than one value I was told you can concatenate the print_r so this works in the above example:

$confirmation .= print_r( $data->id, true )." <br/> ".print_r($data->login, true);
return $confirmation;