[Solved] submitting form to self in IE with one text field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

[Solved] submitting form to self in IE with one text field

Post 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.
Last edited by Hibba on Thu Dec 23, 2004 4:50 pm, edited 2 times in total.
User avatar
Slippy
Forum Contributor
Posts: 113
Joined: Sat Jul 12, 2003 11:31 pm
Location: Vancouver eh!

Post 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)&#123;**DO NOTHING?;&#125;">
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.
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post 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.
User avatar
Slippy
Forum Contributor
Posts: 113
Joined: Sat Jul 12, 2003 11:31 pm
Location: Vancouver eh!

Post 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?
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post 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.
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post 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.
User avatar
Slippy
Forum Contributor
Posts: 113
Joined: Sat Jul 12, 2003 11:31 pm
Location: Vancouver eh!

Post by Slippy »

Wow, that is a weird phenomenon... looks like M$oft does it again. Glad you figured it out.
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post by Hibba »

Can't say I figured it out, but just passing along information.
Merry Christmas to all!
Post Reply