Search code examples
htmlformskeyboardform-submitsmartphone

Open button on keyboard immediately sends form


I have a form like this:

<form action="form_send.php" method="post">
<table>
        <tr>
            <td><label for="address">address</label></td>
            <td><input type="text" id="address" name="address" tabindex="1" /></td>
        </tr>
        <tr>
            <td><label for="country">country</label></td>
            <td><input type="text" id="country" name="country" tabindex="2" /></td>
        </tr>
        <tr>
</table>
<input type="submit" value="Submit" tabindex="3" />
</form>

If the user opens Safari or other browser on his/her smartphone and fills out the text fields, he has the possibility to click on Open. If this button is pressed the form is immediately sent.

Is there a possibility that the user first jumps to the second text field before he can submit the form?

I tried to use tabindex but that doesn't helped me. I know I can make fields mandatory with PHP/Javascript, but the fields shouldn't be mandatory.


Solution

  • It might be pressing enter for the user. You can prevent this by intercepting keystrokes.

    This bit of code (jQuery) will prevent forms from being submitted by pressing ENTER.

    $('form').keypress(function(e){
        if(e.keyCode === 13){
            e.preventDefault();
         }
    });