$("#newsletterForm").validator().on("submit", function (event) { if (event.isDefaultPrevented()) { // handle the invalid form... formErrorNs(); submitMSGNs(false, "You did not fill in the form properly"); } else { // everything looks good! event.preventDefault(); submitFormNs(); } }); function submitFormNs(){ // Initiate Variables With Form Content var name = $("#nome").val(); var cognome = $("#cognome").val(); var email = $("#email").val(); var consenso = $("#consenso").val(); var type = $("#type").val(); var lingua = $("#lingua").val(); var inviato = $("#submit").val(); var verGoo = $("#recaptchaResponse").val(); $.ajax({ type: "POST", url: "https://www.villaroberta.net/sending-form-hmi.php", data: "nome=" + name + "&cognome=" + cognome + "&email=" + email + "&type=" + type + "&lingua=" + lingua + "&inviato=" + inviato + "&consenso=" + consenso + "&recaptcha_response=" + verGoo, success : function(text){ if (text == "successNs"){ formSuccessNs(); } else { formError(); submitMSGNs(false,text); } } }); } function formSuccessNs(){ $("#newsletterForm")[0].reset(); submitMSGNs(true, "Successful registration!") } function formErrorNs(){ $("#newsletterForm").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-primary"; } else { var msgClasses = "h3 text-center text-danger"; } $("#msgSubmitNs").removeClass().addClass(msgClasses).text(msgNs); }