Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google chrome submits form even if there is no SUBMIT button

This bug/feature cropped up in one of my pages when viewed in google chrome so i wrote a test page which looks like this

<body>
 <form action="loginhandler.php">
      <input type="text" id="name">
      <input type="text" id="lastname">
      <input type="button" value="Login">
 </form>
</body>

Here you can see, the input type is NOT of type submit. So if you press ENTER KEY on IE,Firefox,Opera, nothing happens and that is the expected behavior. But if you press enter on chrome, it SUBMITS regardless of whether the input type is submit or not.

My question , is this a default feature/bug of chrome or am i doing something wrong here. ?

like image 521
Udayaditya Barua Avatar asked Aug 04 '10 07:08

Udayaditya Barua


2 Answers

To cite section 4.10.21.2 of the HTML5 specification:

"If the form has no submit button, then the implicit submission mechanism must just submit the form element from the form element itself."the form element itself."

Therefore I believe Chrome's behaviour to be correct, although I think other browsers do this as well. You can catch/block/process form submission by listening to the "submit" (e.g. to block it) event.BlockquoteBlockquotethe form element itself."

like image 132
Peter Beverloo Avatar answered Oct 07 '22 15:10

Peter Beverloo


Not even Chrome, most of browsers submit once you press enter (even there is not submit button) when cursor in input.

like image 3
PPShein Avatar answered Oct 07 '22 15:10

PPShein