Created
April 22, 2019 16:42
-
-
Save with-shrey/b5d9bbb8e2b16e36e5bc5a5803d1cdfa 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 = $(".subscription-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() { | |
$("#sub-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/subscribe.php", | |
data: form_data1, | |
success: function() { | |
$("#sub-btn").removeClass("fa-spinner fa-spin").addClass("fa-paper-plane"); | |
$("#s-email").val(""); | |
contactResault.addClass("correct"); | |
contactResault.html("Subscription successful. You will now receive updates from us."); | |
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"); | |
} | |
$("#sub-btn").removeClass("fa-spinner fa-spin").addClass("fa-paper-plane"); | |
contactResault.addClass("incorrect"); | |
contactResault.html("Please fill in your email id"); | |
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