$("#contactForm").validator().on("submit", function (event) { if (event.isDefaultPrevented()) { // handle the invalid form... formError(); submitMSG(false, "Non hai compilato il modulo correttamente"); } else { // everything looks good! event.preventDefault(); submitForm(); } }); function submitForm(){ // Initiate Variables With Form Content // var name = $("#nome").val(); var email = $("#emailA").val(); var emailDa = $("#emailDa").val(); var oggetto = $("#oggetto").val(); var idImmobile = $("#idIm").val(); var messaggio = $("#messaggio").val(); var consenso = $("#consenso").val(); var robots = $("#verifica").val(); var linguaMail= $("#lingua").val(); var verGoo = $("#recaptchaResponse").val(); $.ajax({ type: "POST", url: "https://www.hotellorenz.it/send-prodotto-ho.php", data: "nome=" + name + "&email=" + email + "&idOfferta=" + idImmobile + "&emailDa=" + emailDa + "&oggetto=" + oggetto + "&messaggio=" + messaggio + "&consenso=" + consenso + "&lingua=" + linguaMail + "&verifica=" + robots + "&recaptcha_response=" + verGoo, success : function(text){ if (text == "success"){ formSuccess(); } else { formError(); submitMSG(false,text); } } }); } function formSuccess(){ $("#contactForm")[0].reset(); submitMSG(true, "Messaggio Inviato con Successo!") } function formError(){ $("#contactForm").removeClass().addClass("shake animated").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function(){ $(this).removeClass(); }); } function submitMSG(valid, msg){ if(valid){ var msgClasses = "h3 text-center tada animated text-success"; } else { var msgClasses = "h3 text-center text-danger"; } $("#msgSubmit").removeClass().addClass(msgClasses).text(msg); }