Skip to content

Instantly share code, notes, and snippets.

@thomasmb
Created December 9, 2020 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasmb/7ac71e462ba733c1155eb86aa7f76782 to your computer and use it in GitHub Desktop.
Save thomasmb/7ac71e462ba733c1155eb86aa7f76782 to your computer and use it in GitHub Desktop.
Contact Form 7 prevent duplicate submissions
// Once the form is submitted, disable the button
$(document).on( 'submit', '.wpcf7-form', function() {
var $submit = $(this).find('[type=submit]');
// Disable the button
$submit.attr('disabled', true)
// Create a backup of the button text
.data( 'original-text', $submit.text() )
// Change the button text to indicate sending
.text( 'Sending…' );
});
// After submit, re-enable the button
$(document).on( 'wpcf7submit', '.wpcf7', function (e) {
var $submit = $(this).find('[type=submit]');
// Enable the button again
$submit.removeAttr('disabled');
// Reset the button text
if( $submit.data( 'original-text' ) ) {
$submit.text( $submit.data( 'original-text' ) );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment