【问题标题】:Send gravity form entries to 3rd party API将重力表单条目发送到 3rd 方 API
【发布时间】:2016-11-15 03:25:08
【问题描述】:

我目前正在尝试将信息从 Gravity Froms 发送到第 3 方 API。我知道 Gravity Forms 中有 gform_after_submission 挂钩,可以将信息发送到第 3 方 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 提供的不同方法发送信息。在这种情况下,我正在为用户创建一个表单,以输入新的奖励卡或转移卡。基本上我必须查看我的表单并调用一个方法来检查旧卡号,发送一个调用来添加/更新客户,等等。

现在使用 Gravity Forms gform_after_submission,我怎样才能实现将信息输入到 API 上的正确方法所需的一切。请理解这是我第一次将信息从 Gravity Forms 发送到这样的 API。

【问题讨论】:

    标签: php wordpress forms api gravity-forms-plugin


    【解决方案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 );
    

    希望我已经解释清楚并帮助您更好地理解事物..您可以根据需要更改表单数据 祝你好运。

    【讨论】:

    • 可能对其他人有所帮助。您还可以使用这些 wordpress 功能发出帖子请求-> wp_remote_postwp_safe_remote_post
    • @Parth Goswami 你能帮我解决我的问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 2014-10-28
    • 2015-07-27
    相关资源
    最近更新 更多