Pressing Enter submits the form

  • Palmerston_House
    Asked on August 8, 2016 at 4:48 AM

    Under testing, when a user presses the Enter key to separate a paragraph of text or to jump to the next field it submits the half completed form.

    Is it possible to stop this action and require the submit button only to be clicked on?

     

    Thanks, Alex.

  • Elton Support Team Lead
    Replied on August 8, 2016 at 6:09 AM

    That's the normal behavior of the form when you do not have required fields left.

    There are two ways to stop it from happening.

    1. This one is easy, simply add a required captcha field at the bottom of your form. This should prevent your form from submitting when the enter key is pressed.

    Captcha field is under Quick fields.

    Pressing Enter submits the form Image 1 Screenshot 20

    2. This one requires using the form source code. When you embed your form, you have to use your form source code and append the following script at the bottom of your form source code so when the enter key is pressed, it won't trigger the submit button.

    <script type="text/javascript">

    function stopRKey(evt) {

      var evt = (evt) ? evt : ((event) ? event : null);

      var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

      if (evt.keyCode == 13 && node.nodeName != "TEXTAREA")  {return false;}

    }

    document.onkeypress = stopRKey;

    </script>

    Hope this helps!