How to receive REMOTE POST response data and print to Gravity Forms confirmation page

时间:2016-10-20 19:22:43

标签: gravity-forms-plugin

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 个答案:

答案 0 :(得分:0)

假设一切都是同一提交过程的一部分,您应该能够使用gform_confirmation钩子而不是 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;
}

这假定:

  • 您的确认已配置为文字(不是网页或重定向)

您需要:

  • 将过滤器名称中的“123”更新为您的表单ID
  • 更新wp_remote_post()以实际使用适用于您的请求的变量
  • 更新$确认以包含您想要的响应中的实际内容

答案 1 :(得分:0)

从@ dave-from-gravity-wiz答案开始,为了简单起见,我在github API上使用GET not POST

""

这将获取您可以在url上看到的json表,并且仅在表单提交确认或您将其更改为的任何键标签上的响应中打印“ id”号。如果您想显示多个值,我们被告知您可以连接print_r,这样可以在上面的示例中起作用:

+