Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is going on? IE 7 Simple POST Problem

Status
Not open for further replies.

bitwise

Programmer
Mar 15, 2001
269
US
Does anyone have any idea what is going on here? Look at this super simple form first and I'll explain:

Code:
<?php
if(isset($_POST['submit'])) {
	echo $_POST['test'] . "<br>";
}
?>

<form method=post action="form.php">
<input type=text name=test value="">
<input type=submit name=submit value="Submit">
</form>

In IE 7.0 if you hit the "Enter" key after your done typing in the textbox the form loses its value and doesn't actually POST the data (i.e. no echo of the value of the 'test' variable). In Mozilla 2.0 there is no problem. When you hit "Enter" the value of 'test' is echo'd to the page.

Now, if you add another input in the above form like so:

Code:
<?php
if(isset($_POST['submit'])) {
	echo $_POST['test'] . "<br>";
}
?>

<form method=post action="form.php">
<input type=text name=test value="">
<br>
[b]<input type=text name=dummy value="">[/b]
<input type=submit name=submit value="Submit">
</form>

This works just fine in IE 7.0 when you hit enter! What the heck is going on? Why do you have to have 2 input fields in IE 7 for the POST to work after hitting "Enter". Any thoughts or work-arounds?

Thank you!
 
you should enquote all your param values.

Code:
if(isset($_POST['submit'])) {
    echo $_POST['test'] . "<br>";
}
?>

<form method="post" action="form.php">
<input type="text" name="test" value="">
<input type="submit" name="submit" value="Submit">
</form>

however it may be more likely to be something to do with whether or not the submit button gets sent with an enter key in different browsers - the same problem for automated js submit methods. either way it's not a php problem.

perhaps better to check always for a value that you KNOW must be present.
 
Hey jpadie, in the real form/html/php code all my param's are in double-quotes. Furthermore, I do check if a value is submitted and valid or not via javascript...my point is, even when a value is in the field and valid, when you hit the Enter key in IE 7 on a form with only one text field, it will just lose its value and doesn't actually POST the data (i.e. if(isset($_POST['submit'])) returns false). Go ahead and try it yourself.

I'm wondering if there is a work around or fix for this? Thanks.
 
as alluded to above, it may be that because the submit button is not PRESSED then IE7 is not sending it. I don't have IE7 to be able to test it myself.

can you try a script with just

Code:
echo "<pre>".print_r($_POST, true);
?>

<form method="post" action="form.php">
<input type="text" name="test" value="">
<input type="submit" name="submit" value="Submit">
</form>
 
No offense, but if you don't have IE 7 please don't respond. As for your last comments, of course the button is NOT pressed. That's the problem. The form is only posted when the button IS pressed, but the problem is that it should post when you hit the "Enter" key WITHOUT pressing the button. The form in my first post works fine in Mozilla, and it also works fine in IE 7 with the one condition that there are 2 or more text fields in the form. The problem is exactly as I stated in my first post.

To reiterate. This code below does not evaluate to TRUE with only one text field item in the form.

Code:
if(isset($_POST['submit']))

It does actually POST and set the var $_POST['test'] b/c if you remove the isset() check you will see the value, but you need to test the isset() to avoid errors.

PS: The above code you posted is functionally equivalent to my orig post. That's not really the issue I'm getting at.
 
but the problem is that it should post when you hit the "Enter" key WITHOUT pressing the button

why? where in the relevant RFC does it say that a browser must submit a button value for a button that is not pressed? this is an individual choice for a browser. and even if it were mandatory, IE has long had a history of ignoring RFCs. Either way it's NOT a php issue.

apologies for trying to help.
 
I understand that it's not a php issue. I know this. However, PHP programmers deal with this kind of thing all the time so I thought it was relevant to post to this forum.

where in the relevant RFC does it say that a browser must submit a button value for a button that is not pressed?

Nevertheless, the bottom line is this: Mozilla and IE both submit forms when the enter key is pressed in an input type=text on a form. So, it must be dealt with. The problem is that in IE 7 with ONE textfield item this code does not evaluate to true:

Code:
if(isset($_POST['submit']))

But is STILL submits the form and you lose the ability to process it because as a PHP programmer you are checking that the form is submitted at the top of the php page. This behaivor is not user friendly. However, it works just fine with 2 text field forms. The problem ONLY exists on a form with only 1 text field.
 
the php answer is to test for the presence of a KNOWN element (like the text element). unless you genuinely care about the value of the button pressed, then this is my preferred solution to cover the use cases across the browsers and js implementations where this occurs.

your issue, in other respects, would be better reported to microsoft, if you believe it to be a bug, or perhaps there are other fora that could give you more support.

I have, however, installed a VM with iE7 and can confirm that I too am seeing the same behaviour.
 
Ok, thanks jpadie. I will just look at the known element directly. Thank you for installing IE7 and testing. I think this might be a bug in IE7. I mean, I can't imagine this is the desired behavior, but whatever, it is what it is. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top