function infoAggiornate(e) { swal({ type: 'success', text: e, timer: 1500, timerProgressBar: true, showConfirmButton: false }) }; if ($("#contattiForm").length > 0) { // needs for recaptacha ready grecaptcha.ready(function () { // do request for recaptcha token // response is promise with passed token $('#contattiForm').parsley().on('form:error', function () { swal({ title: "Errore", text: "Per procedere รจ necessario completare tutti i campi obbligatori", type: "error", showConfirmButton: true }); }).on('form:submit', function () { $('#contattiForm').find('input[type=submit]').prop('disabled', true); grecaptcha.execute('6LeFBiIsAAAAAHr8SlQZJ0Tx_UV8PNBiYikQr_of', {action: 'homepage'}) .then(function (token) { // add token to form document.getElementById('g-recaptcha-response').value = token; form = $('#contattiForm'); $.ajax({ url: "https://www.gm-motors.com/assets/ajax/invia-mail.php", type: "POST", data: form.serialize(), beforeSend: function (data){ const form = document.querySelector("form"); form.querySelectorAll("button").forEach(btn => { btn.disabled = true; }); form.querySelectorAll("a").forEach(a => { a.style.pointerEvents = "none"; a.style.opacity = "0.6"; }); }, success: function (data) { if (data.status == "success") { infoAggiornate(data.message); setTimeout(function () { window.location = 'https://www.gm-motors.com' }, 2000); } else if (data.status == "error") { $('#contattiForm').find('input[type=submit]').prop('disabled', false); swal({ title: "Errore", text: data.message, type: "error", showConfirmButton: true }); return false; } }, }); }); return false; }); }); }