$("#contactForm").validator().on("submit", function (event) { if (event.isDefaultPrevented()) { // handle the invalid form... formError(); submitMSG(false, "You did not fill in the form properly"); } 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= $("#linguaMail").val(); $.ajax({ type: "POST", url: "https://www.villaroberta.net/send-prodotto.php", data: "nome=" + name + "&email=" + email + "&idOfferta=" + idImmobile + "&emailDa=" + emailDa + "&oggetto=" + oggetto + "&messaggio=" + messaggio + "&consenso=" + consenso + "&lingua=" + linguaMail + "&verifica=" + robots, success : function(text){ if (text == "success"){ formSuccess(); } else { formError(); submitMSG(false,text); } } }); } function formSuccess(){ $("#contactForm")[0].reset(); submitMSG(true, "The message has been successfully sent!") } 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); }