Skip to content

Instantly share code, notes, and snippets.

@uprise10
Created May 25, 2021 19:05
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 uprise10/ed72c62c071a369fddb2434f419978ae to your computer and use it in GitHub Desktop.
Save uprise10/ed72c62c071a369fddb2434f419978ae to your computer and use it in GitHub Desktop.
Prevent double click on submit button in Gravity Forms
<?php
add_action( 'gform_enqueue_scripts', 'your_prefix_add_scripts' );
function your_prefix_add_scripts($form) {
echo '<script>
document.addEventListener( "DOMContentLoaded", function( e ) {
if ( typeof jQuery !== "undefined" ) {
jQuery(document).on( "click", "#gform_' . $form['id'] . ' [type=submit]", function(e) {
if( jQuery(this).data("isclicked" ) === true ) {
e.preventDefault();
return false;
}
jQuery(this).css("opacity", 0.2).data("isclicked", true);
});
}
});
</script>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment