Created
April 22, 2019 16:43
-
-
Save with-shrey/3ade4fa5d0ea8c805002157db6607e07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var contactForm = $(".contact-form"); | |
if(contactForm.length){ | |
var contactResault = $("body").append("<span class='form-resault'></span>").find(".form-resault"); | |
contactForm.each(function(){ | |
var this_form = $(this); | |
var contactFormInput = this_form.find(".form-control"); | |
this_form.on("submit", function() { | |
$("#cnt-btn").removeClass("fa-paper-plane").addClass("fa-spinner fa-spin"); | |
var form_data1 = $(this).serialize(); | |
if(!contactFormInput.parent().hasClass("input-error") && contactFormInput.val()){ | |
$.ajax({ | |
type: "POST", | |
url: "php/contact.php", | |
data: form_data1, | |
success: function() { | |
$("#cnt-btn").removeClass("fa-spinner fa-spin").addClass("fa-paper-plane"); | |
$("#c-name").val(""); | |
$("#c-email").val(""); | |
$("#c-phone").val(""); | |
$("#c-message").val(""); | |
contactResault.addClass("correct"); | |
contactResault.html("Your message has been sent. Our team will get back to you in 2 business days."); | |
setTimeout(function(){ | |
contactResault.removeClass("incorrect").removeClass("correct"); | |
}, 3000); | |
} | |
}); | |
} else{ | |
if(contactFormInput.val() === ""){ | |
var contactFormInputEmpty = contactFormInput.filter(function(){ | |
return $(this).val() === ""; | |
}); | |
contactFormInputEmpty.parent().addClass("input-error"); | |
} | |
$("#cnt-btn").removeClass("fa-spinner fa-spin").addClass("fa-paper-plane"); | |
contactResault.addClass("incorrect"); | |
contactResault.html("You must fill in all the required fields."); | |
setTimeout(function(){ | |
contactResault.removeClass("incorrect").removeClass("correct"); | |
}, 3000); | |
} | |
return false; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment