Jump to content

Watch out for this IE behavior


roopurt18

Recommended Posts

Not sure how many people are aware of this, but I just spent 10 minutes going "WTF?!"

 

Simple form with a text field and a button with name='add_group'

 

On the processing page is a check:

if($this->_view == 'add_group' && isset($_POST['add_group'])){
  // ...
}

 

Basically the form processor checks that we're on the right page and we got here from the correct submit button.

 

It wasn't working on IE6 because I was hitting enter instead of clicking the button.  I would type in the text field, hit enter, and since I didn't technically click the button, 'add_group' wasn't set in $_POST.

 

Of course, FF behaved properly.

Link to comment
Share on other sites

So I just use firefox, even my school uses firefox.

 

Really? That's odd. That's never the case!

 

My university strongly advises all members of the campus community against using IE. :)

 

It wasn't working on IE6 because I was hitting enter instead of clicking the button.  I would type in the text field, hit enter, and since I didn't technically click the button, 'add_group' wasn't set in $_POST.

 

Have you found a fix that doesn't hinge on not using IE, or otherwise forcing the user to make the change? If not, how about this:

 

Is it necessary to check for the submit button? Instead of checking:

 

if(isset($_POST['add_group']))

 

would it work to check this?

 

if(isset($_POST['text_entry_field']))

 

You'd have to make sure that the name of the text entry field is unique, and that it would indicate that you're coming from the correct form.

 

Link to comment
Share on other sites

It wasn't working on IE6 because I was hitting enter instead of clicking the button.  I would type in the text field, hit enter, and since I didn't technically click the button, 'add_group' wasn't set in $_POST.

 

Of course, FF behaved properly.

According to the HTML spec:

If a control doesn't have a current value when the form is submitted, user agents are not required to treat it as a successful control

And since the default value for a button is nothing, IE is following the spec.

Link to comment
Share on other sites

I'd have to disagree.  Inputs of type button or submit are almost always given a value attribute, so the question is when a form is submitted do you send all of the button / submit inputs or just the one that was depressed?  Most browsers default to the one that was depressed.  So when submitting a form with a single button / submit input, we'd expect to see it in $_POST.

 

Now, if you have a form that consists purely of a text input and a submit button, does the specification say that pressing [enter] while focus is in the text input that the form should be submitted?  I would guess that it doesn't, but most browsers do support that behavior.

 

So, if pressing enter causes the form to be submitted, why would the button not be sent as if it were clicked?  It just seems counter-intuitive to me.

 

Also, it's not mentioned in my OP, but the submit button does have a value attribute set.

 

MS does follow outside specifications in some areas, but I don't think this is one of them.  Also, when they do decide to follow standards, they usually pick the most obscure parts of the specification that make the developers' lives torture.

Link to comment
Share on other sites

Hmmm, i just did a test and it works across the board

 

<?php
echo '<pre>', print_r($_POST), '</pre>'
?>
<form action="" method="post">
<input type="text" value="" name="field_1"  />
<input type="text" value="" name="field_2"  />
<input type="text" value="" name="field_3"  />
<input type="text" value="" name="field_4"  />
<input type="submit" value="Pressed or Not" name="form_button" />
<button name="test button" >tasdfa</button>
</form>

 

And I am not sure if your button type was a submit or not, but you did say if you press it and didnt mention any javascript. It works fine in IE for me

Link to comment
Share on other sites

Does exactly what I described here:

http://ns2271.serverpowered.net/test/ietest.php

 

Type hello in the box and immediately hit enter.

 

Then type hello in the box and click on the button.

 

<?php
  if(!empty($_POST)){
    echo '<pre>' . print_r($_POST, true) . '</pre>';
  }
  echo <<<HTML
    <form action="" method="post">
      <input type="text" name="the_text" size="16"/>
      <input type="submit" name="the_submit" value="Go" />
    </form>
HTML;
?>

Link to comment
Share on other sites

Looks like if you add another input it works as expected. I understand why people hate microsoft

i guess IE defeats FF in this case (nice roopurt )

thumbs up for IE in this case

 

Um... no, IE loses. It behaves differently if you have two inputs than with one input. Since when is that intuitive?

Link to comment
Share on other sites

Have you found a fix that doesn't hinge on not using IE, or otherwise forcing the user to make the change?
Speaking of which.. I wander how long it will be until somebody someone uses the security problems in IE to make it uninstall itself and install Firefox when you visit their site, automatically.

That would be so awesome!

Link to comment
Share on other sites

Huh? Pressing enter is the same as clicking submit (unless it's a <textarea>).

 

what if you 3 buttons ???

in single submit button in FF yes but in IE you have to be sure that the pointer or focus form is in that button before you hit enter for you to be able to get the value of that button..

 

try the sample the roopurt provided

Link to comment
Share on other sites

I think there is usually only one submit button when there is no <textarea> involved. I think it is basically a standard to only have one submit button in such cases except in very rare exceptions. Or if the form itself is comprised of nothing but submit buttons (in which case it's kind of moot since hitting enter will only submit the one you click on, and clicking on it will submit it lol)

Link to comment
Share on other sites

I'd have to disagree.  Inputs of type button or submit are almost always given a value attribute, so the question is when a form is submitted do you send all of the button / submit inputs or just the one that was depressed?  Most browsers default to the one that was depressed.  So when submitting a form with a single button / submit input, we'd expect to see it in $_POST.

 

Now, if you have a form that consists purely of a text input and a submit button, does the specification say that pressing [enter] while focus is in the text input that the form should be submitted?  I would guess that it doesn't, but most browsers do support that behavior.

 

So, if pressing enter causes the form to be submitted, why would the button not be sent as if it were clicked?  It just seems counter-intuitive to me.

 

Also, it's not mentioned in my OP, but the submit button does have a value attribute set.

 

MS does follow outside specifications in some areas, but I don't think this is one of them.  Also, when they do decide to follow standards, they usually pick the most obscure parts of the specification that make the developers' lives torture.

That doesn't make sense in the general case.  All buttons have "values" -- that's the only way to specify their label.  However, you wouldn't want all "unclicked/unpressed" buttons to be submitted as successful name/value pairs, right? Just because you expect it to be submitted doesn't mean the browser has been to psychic -- and spec doesn't require it.  As for the submit-on-enter argument, that's another can of worms entirely.  You want a single submit button to be treated as a magical auto-valued auto-clicked button if and only if it's the only button in the form... that's what the spec doesn't agree with.  All buttons are created equal.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.