Page 1 of 1
[Solved] submitting form to self in IE with one text field
Posted: Wed Dec 22, 2004 10:11 pm
by Hibba
What I have is just a basic form, but in IE, pressing enter when in a field seems to refresh the page. This php that I use goes through a few different forms (questions) after each submit. Some of them will work if enter is pressed, others will not.
Only happens in IE.
action of the form is PHP_SELF
Thanks for any advice.
Posted: Wed Dec 22, 2004 10:41 pm
by Slippy
I think that's just how IE handles form input. If you press enter on a form it will submit to the page that the form action is pointing to... in this case PHP_SELF.
You might be able to trap the ENTER key using javascript sort of like (you'll need to modify it a bit (I'm feeling lazy):
Code: Select all
<body onkeydown="if(event.keyCode == 13){**DO NOTHING?;}">
Meaning that if the user presses ENTER in IE; run some code that does... nothing... hopefully solving your problem.
Of course; I like pressing enter to submit a form.
Posted: Wed Dec 22, 2004 10:45 pm
by Hibba
I don't think it submits the form to itself, because that it what I need it to do. I think it refreshes the page that the form action is pointing to.
I don't want the enter key to do nothing, I want it to submit the form like Firefox or Safari or any other decent browser.
Posted: Wed Dec 22, 2004 11:10 pm
by Slippy
Sorry, I must be misunderstanding you... my understanding was that PHP_SELF was a system var that gets replaced with the page that is currently running.
Can you put a stripped out version of the form's code here so that I might try to duplicate the problem that you are experiencing?
Posted: Thu Dec 23, 2004 9:47 am
by Hibba
Here is a simple example that does not work correctly in IE.
Code: Select all
<?php
$UserName = file_get_contents('include.html');
if(isset($_POST['submit'])) {
extract($_POST);
if(!empty($name)) {
echo $name;
}
} else {
$form = "<form name ="myform" method="post" action="". $PHP_SELF."">";
$form .= $UserName;
$form .= "<input type="submit" value="Submit" name="submit">";
$form .= "</form>";
echo $form;
}
?>
So basically, I want it to where you hit enter and it will submit, but in IE it does not do this, it refreshes the page.
Posted: Thu Dec 23, 2004 4:49 pm
by Hibba
Here is the solution to an interesting problem. In Internet Explorer, if you have a form with one text field and it POSTS to itself, IE will not correctly perform that action. If there are more than one field, there is no problem. The trick is to pass a hidden variable and use that rather than using sumbit as an if(isset(sumbit) or some kind of validation like that.
Here is the URL for a better explanation <
http://www.sitepoint.com/forums/showthread.php?t=46675>
Might I say that this is not a problem in other browsers, like Firefox or Safari.
Posted: Thu Dec 23, 2004 6:18 pm
by Slippy
Wow, that is a weird phenomenon... looks like M$oft does it again. Glad you figured it out.
Posted: Thu Dec 23, 2004 7:20 pm
by Hibba
Can't say I figured it out, but just passing along information.
Merry Christmas to all!