我有一个内置在Elementor中的表单,我希望将其插入,处理数据并转发到第三方,然后在“确认”卡上显示数据。
我可以将整个过程构建为一个单独的页面,使用CSS将每个页面设置为不显示,然后在接收AJAX响应时使用JS显示/隐藏。这并不理想,因为它会在关闭JS的情况下中断。
我还没有找到合适的Elementor钩子和方法来填充PHP的新页面,有谁有经验吗?
发布于 2019-03-30 09:34:43
有几种方法可以将数据从Elementor web表单发布到另一个url。
一种是使用许多应用程序接口集成,如Mailchimp、ActiveCampaign、Zapier等(参见https://docs.elementor.com/article/281-form-faq)和(https://docs.elementor.com/category/405-integrations)
另一种(非常有限的方法)是在提交后使用表单的Action并选择"redirect“,然后在url中使用每个字段的短代码作为单独的数据字符串,例如:
Mysite.com/谢谢?fname=field id="fname"&lname=field id="lname“
您甚至可以在Elementor中构建您的/感谢/页面来获取数据,并使用表单域数据填充Elementor元素,如文本、标题、链接等。例如,我可以将一个文本元素放到/thank You /页面上,然后选择dynamic而不是在文本区域中键入,然后从dynamic下拉菜单中选择"request参数“,对于"type”选择GET,对于param name使用您唯一的url键,如fname,lname等。您甚至可以设置前缀、后缀甚至回退文本。
最后,这里是关于如何后端代码向外部传递数据(https://developers.elementor.com/forms-api/#Form_New_Record_Action)的概述。
// A send custom WebHook
add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) {
//make sure its our form
$form_name = $record->get_form_settings( 'form_name' );
// Replace MY_FORM_NAME with the name you gave your form
if ( 'MY_FORM_NAME' !== $form_name ) {
return;
}
$raw_fields = $record->get( 'fields' );
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}
// Replace HTTP://YOUR_WEBHOOK_URL with the actuall URL you want to post the form to
wp_remote_post( 'HTTP://YOUR_WEBHOOK_URL', [
'body' => $fields,
]);
}, 10, 2 );还有一个包含更多示例的线程,它使用该模板作为入门,与不同的API集成(https://github.com/elementor/elementor/issues/2397)
https://stackoverflow.com/questions/52787572
复制相似问题