Last active
July 20, 2023 17:46
-
-
Save jaredatch/438336f0975acfff5f18bc046eb146d4 to your computer and use it in GitHub Desktop.
WPForms prevent duplicate / double form entry submissions
This file contains 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
<script type="text/javascript"> | |
/** | |
* Prevent double entry submissions. | |
* | |
* Steps to install: | |
* 1 - Download and activate the "Insert Headers and Footers" plugin (by WPBeginner) | |
* 2 - Go to Settings > Insert Headers and Footers | |
* 3 - Paste this entire code snippet | |
* 4 - Save | |
*/ | |
jQuery(function($){ | |
$('.wpforms-form').on('submit',function(e){ | |
var $form = $(this), | |
validator = $form.validate(), | |
valid = validator.form(); | |
if (valid) { | |
if ($form.data('submitted') === true) { | |
// Previously submitted - don't submit again | |
alert('Form already submitted. Please wait.'); | |
e.preventDefault(); | |
} else { | |
// Mark it so that the next submit can be ignored | |
$form.data('submitted', true); | |
$form.find(':submit').text('Sending...'); | |
} | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!