我不熟悉重力形式的钩子(Hook)。 我创建了 2 个注册流程表单,它们以单一模式显示,但在不同的 div 中调用。我想使用 gform_after_submission 将这些数据从 2 个表单发送到第三方应用程序,在提交特定表单(最后一个表单)后将条目数据发送到第三方。
但是这样做:
add_action( 'gform_after_submission_2', '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' ),
);
$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
}
将只允许我从指定的表单 ID 中获取输入字段。
我怎么可能也从其他表单中获取条目,以便我可以将其包含并发布到第三方 url?
提前致谢。
最佳答案
因为您在 add_action 本身中指定了表单 ID,所以您仅在提交 ID 为 2 的重力表单时才运行您的函数。如果您希望它针对多个提交运行,但随后将其限制为特定的表单 ID,那么更像这样:
add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
if( $form->id == 2 || $form->id == somenumber ) {
$post_url = 'http://thirdparty.com';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'message' => rgar( $entry, '3' ),
);
$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
}
}
如果您不处理该对象,您可能需要使用 $form['id']
。其中之一会起作用。缺点是您必须知道要使用的表单的 ID。当查看您创建的表单表格时,很容易在后端找到它,但它就是这样......
关于php - 提交特定表格后,Gravity Forms 将多个表格组合的条目数据发送给第三方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32599066/