Domanda

Mi sta solo chiedendo se puoi provare a assistere.

Ho un modulo di registro in WordPress che viene pubblicato su un database utente.Devo anche superare le stesse informazioni sulla forma a un webhook (Zapier).

Capisco che non puoi avere 2 azioni di forma per una forma, tuttavia ho idealmente bisogno di trovare il modo migliore per inviare entrambe le serie di informazioni;uno per il database e uno al link di webhook.

Un esempio della mia pubblicazione del mio codice al mio database.Ho bisogno che questo postare anche a

https://zapier.com/examplehook/

<form name="register_form" id="register_form<?php $template->the_instance(); ?>" action="$template->the_action_url( 'save-register' ); ?>" method="post”>
.

Stavo pensando di usare un evento onclick per eseguire una funzione JavaScript che fa anche un'azione di forma simultanea.Sono confuso se questo funzionerebbe però.

// Codice modificato

$('#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
                });
            });
        }
    });
.

Qualsiasi suggerimento sarebbe l'ideale!

Grazie

È stato utile?

Soluzione

È possibile utilizzare jquery form plugin per questo:

$('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
    });
});
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top