Last active
May 22, 2019 08:14
-
-
Save uamv/f7c9356876d9aa21dae4ca6cd261f66a to your computer and use it in GitHub Desktop.
Disables form submission when pressing Enter, unless user has tabbed to submit button or page advance button.
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
<?php | |
function twxyz_prevent_gform_submission( $form ) { ?> | |
<script type="text/javascript"> | |
jQuery(document).bind('gform_post_render', function(){ | |
jQuery(document).on( 'keypress', '.gform_wrapper', function (e) { | |
var code = e.keyCode || e.which; | |
if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) { | |
e.preventDefault(); | |
return false; | |
} | |
}); | |
}); | |
</script> | |
<?php return $form; | |
} | |
add_action( 'gform_pre_render', 'twxyz_prevent_gform_submission' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment