$("#newsletterFormL").validator().on("submit", function (event) { if (event.isDefaultPrevented()) { // handle the invalid form... formErrorNs(); submitMSGNs(false, "Non hai compilato il modulo correttamente"); } else { // everything looks good! event.preventDefault(); submitFormNs(); } }); function submitFormNs(){ // Initiate Variables With Form Content /*var name = $("#nomeNL").val(); var cognome = $("#cognomeNL").val(); var email = $("#emailNL").val(); var consenso = $("#consenso").val(); var type = $("#type").val(); var idControl = $("#idControl").val(); var interessi = $("#interessi").val(); var localita = $("#localita").val(); var lingua = $("#lingua").val(); var verGoo = $("#recaptchaResponse").val(); var inviato = $("#submit").val();*/ var json = $("#newsletterFormL").serialize(); $.ajax({ type: "POST", url: "https://www.lvigroup.it/send-isc-news.php", //data: "nome=" + name + "&cognome=" + cognome + "&email=" + email + "&localita=" + localita + "&type=" + type + "&lingua=" + lingua + "&inviato=" + inviato + "&consenso=" + consenso + "&recaptcha_response=" + verGoo + "&idControl=" + idControl + "&interessi=" + interessi, data: json, success : function(text){ //alert(text); if (text == "successNs"){ formSuccessNs(); // imposto un refresh di pagina dopo 60 secondi /*setTimeout(function() { window.location.reload() }, 3000);*/ } else { formErrorNs(); submitMSGNs(false,text); // imposto un refresh di pagina dopo 60 secondi setTimeout(function() { window.location.reload() }, 3000); } } }); } function formSuccessNs(){ $("#newsletterFormL")[0].reset(); submitMSGNs(true, "Iscrizione Avvenuta con Successo!") } function formErrorNs(){ $("#newsletterFormL").removeClass().addClass("shake animated").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function(){ $(this).removeClass(); }); } function submitMSGNs(validNs, msgNs){ if(validNs){ var msgClasses = "h3 text-center tada animated text-success"; } else { var msgClasses = "h3 text-center text-danger"; } $("#msgSubmitNs").removeClass().addClass(msgClasses).text(msgNs); }