POST信息到2个区域.PHP / Javascript


POST information to 2 areas. PHP / Javascript

不知道你能不能帮忙。

我有一个注册表单的WordPress正在发布到用户数据库。我还需要将相同的表单信息传递给webhook (Zapier)。

我知道你不能有两个形式的一个形式的行动,但我理想情况下需要找到提交两组信息的最佳方式;一个到数据库,一个到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
                });
            });
        }
    });

任何建议都是理想的!

谢谢

你可以使用Jquery表单插件:

$('form').on('submit', function(event) {
    event.preventDefault();
    var xhr1 = $(this).ajaxSubmit({url: 'http://firsturl'}).data('jqxhr');
    var xhr2 = $(this).ajaxSubmit({url: 'http://secondurl'}).data('jqxhr');
    $.when(xhr1, xhr2).then(function() {
        // both submits succeeded, redirect
    }, function() {
        // error occured
    });
});