Php 向第三方API发送重力表单条目
我目前正在尝试从Gravity向第三方API发送信息。我知道重力表单中有gform_after_提交钩子,用于向第三方API发送信息Php 向第三方API发送重力表单条目,php,wordpress,forms,api,gravity-forms-plugin,Php,Wordpress,Forms,Api,Gravity Forms Plugin,我目前正在尝试从Gravity向第三方API发送信息。我知道重力表单中有gform_after_提交钩子,用于向第三方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(
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_,如何实现将信息输入API上的正确方法所需的一切。请理解,这将是我第一次从重力表单向这样的API发送信息
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函数来发出post请求->wp\u remote\u post和wp\u safe\u remote\u post