Colin McCann Dot Com

Aberrant behavior with single-input forms in IE7

Posted on April 14, 2009 at 9:02 am

These examples show the difference in handling form submissions between Internet Explorer (version 7 tested) and probably any competent browser on the web (read: everything else). Never mind the fact that this sort of browser behavior is contrary to everything you’d expect. Hope this saves someone the three hours it wasted for me.

Submitted form data

$_POST Array
(
)

Apparently this is wrong

This form has two inputs; a text input named “text” and a submit input named “submit”. Pressing enter while the text field has focus submits the form, but only the text field — the submit button is left behind. If you click the submit button, both fields are properly submitted.

You’d think this would work

Apparently this fantastic bug stems from single-input forms, although there doesn’t really seem to be a lot more information than that on the topic. A logical human, when confronted with this altogether idiotic fact, would attempt to do something like add another input field.

This form is identical to the one above, only with the addition of a hidden field “extra” with a blank value. Pressing enter while in the text field acts similar to above, in that both “extra” and “text” are submitted, while “submit” is not. Again, pressing the submit button resolves this issue.

The ugly hack solution

Instead of a hidden field as in the above example, the “extra” field is a type=”text” that is hidden via CSS. Now look what happens: Pressing enter in the text field submits all three fields, exactly as it should. Functionality is identical when clicking the submit button.

Code
2 comments for this entry:
  1. S. Kästle

    I could not believe my eyes when I stumbled upon this issue. Thanks for putting up this issue on your website.

  2. admin

    Quite frustrating, isn’t it? Hopefully posting this helped you save some time.

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...