Skip to content

Instantly share code, notes, and snippets.

@DuckDivers
Created September 26, 2019 22:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DuckDivers/5153144ed5a06e6034c79f7f4213b642 to your computer and use it in GitHub Desktop.
Save DuckDivers/5153144ed5a06e6034c79f7f4213b642 to your computer and use it in GitHub Desktop.
Prevent Contact Form 7 - Multiple Submissions
// Prevent Multiple Clicks on Contact Form 7 Submissions
jQuery(document).on('click', '.wpcf7-submit', function(e){
if( jQuery('.ajax-loader').hasClass('is-active') ) {
e.preventDefault();
return false;
}
});
@crowesam
Copy link

crowesam commented Feb 5, 2020

Will this work if I am trying to hide a button to prevent double click entries on BBPress forum responses?

@DuckDivers
Copy link
Author

This is specifically for class .wpcf7-submit which is for contact form 7.

@lautaropiatti
Copy link

This solution seems to be no longer effective right now. I guess it's because the .ajax-loader never gets the class "is-active". If someone is facing the same issue, maybe these tweaks helps:

// Prevent Multiple Clicks on Contact Form 7 Submissions
jQuery(document).on('click', '.wpcf7-submit', function(e){
    if( jQuery('.wpcf7-form').hasClass('submitting') ) {
         e.preventDefault();
         return false;
    }
});

It's the same logic but I'm relying on the class that CF7 adds to the form, "submitting" (that's basically there until the spinner disappears).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment