I ran across an interesting situation where some users of mine were complaining that a form I created “didn’t work”. Kind of strange to get this complaint after almost a full year of operation. I remember testing the xhtml and css design in both firefox and IE browsers and it all checked out. What I didn’t think of checking was the behavior of browsers when one presses the return key. With the help of Fiddler (thanks to Casey Williams for the Fiddler suggestion) this is what I discovered:

IE Firefox
Submit Button Clicked All inputs $_POSTed All inputs $_POSTed
Return Key Pressed All inputs $_POSTed
except form buttons
All inputs $_POSTed

(For a larger, more detailed image click here)

As you can see, when my IE users were pressing the return key, the button itself was not being $_POSTed. So what right? Well what if you were checking if the submit button was pressed before doing any processing? Like so…

< ?php
if(isset($_POST['button_name'])){
    // validate the user entries...
}
?>

This would fail if the user hit the return key in IE7. I haven’t tested earlier versions.

View the example. Test it in both browsers.

Right now the only thing that was suggested to me was to add a hidden field to mimic the submit button in your form like so:

<form ...>
    <input type="hidden" name="button_name" value="whatever"... />
</form>

That works just fine.

From perusing irc and several forums, the only response as to WHY this happens are comments like “It’s IE, what do you expect?”. I’m already annoyed that IE doesn’t think it has to adapt to web standards, but this ont really caught me off guard.

I’m wondering if any readers might have some input on my inputs ;P

squirting pussy pregnant fuck anal group fuck girl foot fetish femdom asian fuck


2 Responses to “Return key doesn’t play nice in web form using Internet Explorer”

  1. Luke Says:

    I had a really large script that i made stop functioning at one point because of this error and i now use exactly the same solution you use, a hidden variable set to 1 that i check for.

    I get the feeling this might have been implemented eventually on IE but i’m not 100% sure, it caused me alot of headaches.

  2. Thaddeus Says:

    You can say that again.

Post A Comment