Created
December 9, 2020 21:14
-
-
Save thomasmb/7ac71e462ba733c1155eb86aa7f76782 to your computer and use it in GitHub Desktop.
Contact Form 7 prevent duplicate 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
// 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