I have a form that users use to input information about a posting. When complete they click 'Save' to update. However, in some rare cases (10 in 15,000 records) the user has double clicked the save button and caused a double form submission duplicating items for the posting.
I tried using this to prevent it:
$('input[type=submit]').click(function(){
$('input[type=submit]').attr('disabled',true);
//return true;
});
But the problem with this, it works perfectly in Safari / Firefox etc, but does not work in Internet Explorer 8 (and probably not for 6 & 7)
When I press save in IE8, the button is disabled and that's it, no form submission at all.
(I tried it with and without return true;)
The disabled property was first introduced by Microsoft but has since been adopted as a standard by the W3C. So when the form is submitted - either by clicking on the submit button or pressing Enter in a text input field - the submit button will be disabled to prevent double-clicking.
php // Prevent Multi Submit on all WPCF7 forms add_action( 'wp_footer', 'prevent_cf7_multiple_emails' ); function prevent_cf7_multiple_emails() { ?> <script type="text/javascript"> var disableSubmit = false; jQuery('input. wpcf7-submit[type="submit"]'). click(function() { jQuery(':input[type="submit"]').
You can use javascript to forbid two cliks in the submit button, but it does not work if the user use the "back" button of the navigator between the two clicks. On the server side, you can send the form with an unique id kept in the user session (could also be used for CSRF counter-measure).
I'm not sure so this is a complete guess, but it maybe up to your selector there. Try instead:
$('input:submit').click(function() {
$(this).attr('disabled', true);
});#
You may also try to intercept the submit event
itself:
$('form').bind('submit', function(e) {
$(this).find('input:submit').attr('disabled', 'disabled');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With