2016-10-20 53 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