2016-07-12 13 views
1

現在、Gravity FromsからサードパーティAPIに情報を送信しようとしています。第三者のAPIに情報を送信するためにGravity Formsにgform_after_submissionフックがあることを理解しています。重力フォームエントリを第三者APIに送信

add_action('gform_after_submission', 'post_to_third_party', 10, 2); 
function post_to_third_party($entry, $form) { 

    $post_url = 'http://thirdparty.com'; 
    $body = array(
     'first_name' => rgar($entry, '1.3'), 
     'last_name' => rgar($entry, '1.6'), 
     'message' => rgar($entry, '3'), 
    ); 
    GFCommon::log_debug('gform_after_submission: body => ' . print_r($body, true)); 

    $request = new WP_Http(); 
    $response = $request->post($post_url, array('body' => $body)); 
    GFCommon::log_debug('gform_after_submission: response => ' . print_r($response, true)); 
} 

これを使用しようとしていますが、APIが提供するさまざまな方法に基づいて情報を送信する必要があります。このケースでは、ユーザーが新しい報酬カードを入力するか、カードを転送するためのフォームを作成しています。基本的に私は自分のフォームを見て、古いカード番号をチェックするメソッドへの呼び出しを送信し、顧客の追加/更新などの呼び出しを送信しなければなりません。

重力フォームgform_after_submissionを使用して、APIの正しいメソッドに情報を入力するために必要なすべてを達成するにはどうすればよいですか。 Gravity FormsからこのようなAPIに情報を送信するのは初めてです。

答えて

1
function post_to_third_party($entry, $form) { 

//To fetch input inserted into your gravity form// 
$old_card = rgpost('input_6'); 
$new_card = rgpost('input_3'); 

///to send that fetched data to third-party api/// 
$post_url = 'http://thirdparty.com/{APi request}'; 
$body = array(
     'old_card' => $old_card, 
     'new_card' => $new_card, 
); 

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

    $request = new WP_Http(); 
    $response = $request->post($post_url, array('body' => $body)); 

    //response from api whether card is exist or not/// 
    $res = json_decode($response['body'],true); 

    ///here you can put your logic as per the response// 
} 
add_action('gform_after_submission_4', 'post_to_third_party', 10, 2); 

希望私は&はあなたにbetter..youがあなたの必要性 幸運ごとにフォームデータを変更することができ、物事を理解するためのビットを助けうまく説明してきました。

+0

他人を助けるかもしれません。これらのwordpress関数を使って投稿要求 - > 'wp_remote_post'と' wp_safe_remote_post'を作ることもできます –

関連する問題