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('button[type=submit]').prop('disabled', true); grecaptcha.execute('6LeiYEcpAAAAAI2L4ZyQNxtU_dFJwRR4y5mgYPFg', {action: 'homepage'}) // SITE KEY .then(function (token) { // add token to form document.getElementById('g-recaptcha-response').value = token; form = $('#contattiForm'); $.ajax({ url: "assets/ajax/invia-mail.php", type: "POST", data: form.serialize(), success: function (data) { if (data.status == "success") { infoAggiornate(data.message); setTimeout(function () { window.location = 'https://www.fotoevideoimmobili.it/'// URL HOMEPAGE }, 2000); } else if (data.status == "error") { $('#contattiForm').find('button[type=submit]').prop('disabled', false); swal({ title: "Errore", text: data.message, type: "error", showConfirmButton: true }); return false; } }, }); }); return false; }); }); }