Thanks to Jon Leigh for this snippet! If you use Parsley form validation, a reliable form validation library, here’s an easy way to prevent double submissions of forms. This disables the form submission button only once the form passes Parsley’s form validation.
$.listen('parsley:form:validated', function(e){ if (e.validationResult) { /* Validation has passed, prevent double submissions */ $('button[type=submit]').attr('disabled', 'disabled'); } });
I’ve implemented this in a few different places and it works flawlessly! This is especially useful for mobile device users on slow Internet connections where double submissions can be more prevalent. I hope this helps some businesses out there, it’s helped WordPress Developers and Symfony experts alike improve visitor UX while reducing complaints from people who may have been charged twice.