$("#prevForm").validator().on("submit", function (event) { if (event.isDefaultPrevented()) { // handle the invalid form... formError(); submitMSGPrev(false, "Non hai compilato il modulo correttamente"); } else { // everything looks good! event.preventDefault(); submitFormPrev(); } }); function submitFormPrev(){ // Initiate Variables With Form Content var name = $("#nome").val(); var email = $("#emailA").val(); var emailDa = $("#emailDa").val(); var oggetto = $("#oggetto").val(); var idPreventivo = $("#idIm").val(); var messaggio = $("#messaggio").val(); var consenso = $("#consenso").val(); var linguaMail= $("#linguaMail").val(); $.ajax({ type: "POST", url: "https://www.edelweisshotel.it/send-preventivo.php", data: "nome=" + name + "&email=" + email + "&idPreventivo=" + idPreventivo + "&emailDa=" + emailDa + "&oggetto=" + oggetto + "&messaggio=" + messaggio + "&consenso=" + consenso + "&lingua=" + linguaMail, success : function(text){ if (text == "success"){ formSuccessPrev(); } else { formError(); submitMSGPrev(false,text); } } }); } function formSuccessPrev(){ $("#prevForm")[0].reset(); submitMSGPrev(true, "Messaggio Inviato con Successo!") } function formError(){ $("#prevForm").removeClass().addClass("shake animated").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function(){ $(this).removeClass(); }); } function submitMSGPrev(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); }