Skip to content

Instantly share code, notes, and snippets.

@nflint
Created May 13, 2016 23:26
Show Gist options
  • Save nflint/e4a706085ba8777fd5dcb96ce9805bdd to your computer and use it in GitHub Desktop.
Save nflint/e4a706085ba8777fd5dcb96ce9805bdd to your computer and use it in GitHub Desktop.
// Uses this script: https://limonte.github.io/sweetalert2/
var footernewsletterSubscriberFormDetail = new VarienForm("footer-newsletter-validate-detail"),
val_form = new VarienForm("footer-newsletter-validate-detail");
jQuery("#footer-newsletter-validate-detail").submit(function(e) {
if (val_form.validator && val_form.validator.validate()) {
var t = jQuery(this).serializeArray(),
o = jQuery(this).attr("action"),
r = swal({
title: "One moment please...",
showCancelButton: !0,
confirmButtonText: "Submit"
});
swal.enableLoading();
jQuery.ajax({
url: o,
type: "POST",
data: t,
onLoading: r,
success: function(e, t, o) {
swal.close(), swal({
title: "Cool it worked.",
text: t,
type: "success",
confirmButtonColor: "#DD6B55",
confirmButtonText: "Close",
closeOnConfirm: !1
})
},
error: function(e, t, o) {
swal({
title: "Uh oh. ",
text: "It looks like there was a problem with your submission. Please try again later",
type: "error",
confirmButtonColor: "#DD6B55",
confirmButtonText: "Close",
closeOnConfirm: !1
})
}
}), this.reset(), e.preventDefault()
}
});
@nflint
Copy link
Author

nflint commented May 17, 2016

Note to self:
this is the original script
<script type="text/javascript"> //<![CDATA[ var footernewsletterSubscriberFormDetail = new VarienForm('footer-newsletter-validate-detail'); var val_form = new VarienForm('footer-newsletter-validate-detail'); jQuery("#footer-newsletter-validate-detail").submit(function(e) { if (val_form.validator && val_form.validator.validate()) { var postData = jQuery(this).serializeArray(); var formURL = jQuery(this).attr("action"); jQuery.ajax( { url : formURL, type: "POST", data : postData, success:function(data, textStatus, jqXHR) { alert('success'); }, error: function(jqXHR, textStatus, errorThrown) { alert('Failure'); } }); this.reset(); //form field reset e.preventDefault(); //STOP default action e.unbind(); //unbind. to stop multiple form submit. } }); //]]> </script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment