Disable Submission when Pressing Enter

Instructions

  1. Install our free Custom Javascript for Gravity Forms plugin. Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
  2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
Read the Walkthrough

Code

Filename: gw-disable-submission-on-enter.js

/**
 * Gravity Wiz // Gravity Forms // Disable Submission when Pressing Enter
 * https://gravitywiz.com/disable-submission-when-pressing-enter-for-gravity-forms/
 *
 * Instructions:
 * 1. Install our free Custom Javascript for Gravity Forms plugin.
 * Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 * 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 */
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;
    }
} );

Comments

  1. Laurence Lee
    Laurence Lee May 7, 2025 at 2:21 pm

    Hello, is there any way to achive this while using the Gravity Forms Conversational Forms add on? The current snippet doesn’t seem to work with Conversational Forms. Thanks!

    Reply
    1. Roxy Stoltz
      Roxy Stoltz Staff May 8, 2025 at 4:48 am

      Hey Laurence,

      You’re right! I’ve tested this locally and it indeed looks like it doesn’t work with the Gravity Forms Conversational Forms Add-on. I’ve submitted a feature request to look at possibly updating the snippet to support this. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.