只是想知道您是否可以尝试并提供帮助。
我在 WordPress 中有一个注册表单,它正在发布到用户数据库。我还需要将相同的表单信息传递给 webhook (Zapier)。
我知道您不能对一个表单有 2 个表单操作,但是我理想情况下需要找到提交两组信息的最佳方式;一个到数据库,一个到 webhook 链接。
我的代码发布到我的数据库的示例。我需要这个也发布到
https://zapier.com/examplehook/
<form name="register_form" id="register_form<?php $template->the_instance(); ?>" action="$template->the_action_url( 'save-register' ); ?>" method="post”>
我正在考虑可能使用 onclick 事件来运行一个同时执行表单操作的 javascript 函数。不过,我很困惑这是否可行。
//修改后的代码
$('#registerform').validate({ // initialize the plugin
rules: {
first_name: {
required: true
},
last_name: {
required: true
},
user_email: {
required: true,
email: true
},
user_login: {
required: true
},
hear_about_us: {
required: true
},
contact_number: {
required: true
},
address:{
required: true
},
post_code: {
required: true
}
},
submitHandler: function (form) {
$('#registerform').on('submit', function(event) {
event.preventDefault();
var xhr1 = $(this).ajaxSubmit({url: 'https://zapier.com/example-hook/'}).data('jqxhr');
var xhr2 = $(this).ajaxSubmit({url: '/register/'}).data('jqxhr');
$.when(xhr1, xhr2).then(function() {
window.location.replace("/register-step2/");
}, function() {
// error occured
});
});
}
});
任何建议都是理想的!
谢谢