2016-10-20 54 views
0

我很努力获取远程响应数据以在Gravity Forms确认页面上打印。表单中的数据已成功发布到第三方站点,我的日志显示已收到响应数据,但收到的数据未打印到确认页面。如何接收REMOTE POST响应数据并打印到Gravity Forms确认页面

我已经尝试了很多变化,如;

$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; 

我通过插件提交数据,并与过滤器gform_confirmation,gform_after_submission和gform_entry_post_save无济于事都试过了。

在重力形式的许多支持票;我被告知要做到这一点需要额外的脚本。

谢谢你, 理查德

这是我迄今为止该插件的代码。

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)); 

} 
+0

问题不明确。你能否详细说明一下? –

+0

我的表单将数据发送到远程站点。发送的数据在远程站点上创建一个用户。 我的表单中有1个字段为空,这会触发远程站点创建帐号。 我试图将帐号打印到本地站点确认页面。 我的重力形式日志显示响应数据(帐号)由本地站点接收,但我不理解如何将该数据打印到确认页面。 – Richard

回答

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()实际使用适用的变量,你的要求
  • 更新$确认包括来自响应的实际内容要
+0

感谢您的帮助@David。我不确定如何格式化“更新$确认以包含您想要的响应中的实际内容”。尽管我试图让确认页面只打印来自阵列的VTC_ID响应,我希望我可以保存对提交数据库的所有响应(gform_entry_post_save)。 – Richard