HTML submit with only one text input
Moderator: General Moderators
HTML submit with only one text input
I have made a page that has a form and a single input (type='text') on it. The form's action is the same page (that the form is on). When the page re-loads, a PHP script runs that checks to see if the form has been submitted (if($submitForm)). If the form has been submitted, this line is supposed to run: header("Location: http://www.myurl.com...").
Now, the problem is that when I enter something into the text field and press enter, it just reloads the same page with an empty text box. It never goes to the new page that I have specified. The strange thing about it is that if I add another text box (we'll call it txt2) then I enter something into txt1 and press enter, everything works fine (even if txt2 is empty). The "if" script runs and the next page is loaded.
Even stranger yet, the script written the way that I want it to be written (with just one text field) runs fine in Firefox (a Mozilla browser) but it does not run correctly in IE (unless I add the second text field). I have already tried adding a "hidden" field, but that didn't fix the problem. Is there any way that i can have just one text field, enter text, press enter and get to the next page? What is going on here?
Now, the problem is that when I enter something into the text field and press enter, it just reloads the same page with an empty text box. It never goes to the new page that I have specified. The strange thing about it is that if I add another text box (we'll call it txt2) then I enter something into txt1 and press enter, everything works fine (even if txt2 is empty). The "if" script runs and the next page is loaded.
Even stranger yet, the script written the way that I want it to be written (with just one text field) runs fine in Firefox (a Mozilla browser) but it does not run correctly in IE (unless I add the second text field). I have already tried adding a "hidden" field, but that didn't fix the problem. Is there any way that i can have just one text field, enter text, press enter and get to the next page? What is going on here?
- SystemWisdom
- Forum Commoner
- Posts: 69
- Joined: Sat Mar 26, 2005 5:54 pm
- Location: A Canadian South of the 49th Parallel
Code: Select all
<?php
session_start();
if($submitForm)
{
header("Location: http://www.myurl.com/page2.php");
}
$page_type='home';
include("header.php");
?>
<table>
<tr>
<td>
<form action='http://www.myurl.com/page1.php' method='post' name='searchForm'>
<input type='text' name='searchField' value='' size=16>
<input type='submit' name='submitForm' value='Search'>
</form>
</td>
</tr>
</table>
<?php
include("footer.php");
?>- SystemWisdom
- Forum Commoner
- Posts: 69
- Joined: Sat Mar 26, 2005 5:54 pm
- Location: A Canadian South of the 49th Parallel
From the code you have there, how is page2.php ever going to know what the value entered in the textbox was? You're not passing the text to page2.php in any way as is..
Oh, and try not to rely on AutoGlobals, instead use:
or as feyd suggested:
Maybe that helps?
Oh, and try not to rely on AutoGlobals, instead use:
Code: Select all
if(isset($_POST['submitForm']))Code: Select all
if(isset($_POST['searchField']))Maybe that helps?
In response to Feyd: IE DOES send the submit even if you hit enter from a text field. I have many pages with more than one text field and i can enter text into any number of them, and press enter at any time, and the form will be submitted. I just dont know why it wont work with only one text field. (P.S. I have also looked for the field instead of the button and it still does not work)
In response to SystemWisdom: I left part of my code out to keep it simple when I posted it in this forum. There is a place (inside the 'if' statement) that makes the value of the text field into a session variable. Sorry if that was confusing, but that's not the part that I am having problems with.
Still looking for answers....
In response to SystemWisdom: I left part of my code out to keep it simple when I posted it in this forum. There is a place (inside the 'if' statement) that makes the value of the text field into a session variable. Sorry if that was confusing, but that's not the part that I am having problems with.
Still looking for answers....
- SystemWisdom
- Forum Commoner
- Posts: 69
- Joined: Sat Mar 26, 2005 5:54 pm
- Location: A Canadian South of the 49th Parallel
Hmm.. okay, that works... But I still don't see why it wouldn't send the form..
The only thing I can think of now, is maybe your page headers are already sent, and the call to header() is failing??
It is really just a shot in the dark though, maybe try something like this:
Like I said, a shot in the dark, but I really don't see anything wrong with the code you posted.. sounds weird!
The only thing I can think of now, is maybe your page headers are already sent, and the call to header() is failing??
It is really just a shot in the dark though, maybe try something like this:
Code: Select all
if($submitForm)
{
if( !headers_sent() )
header("Location: http://www.myurl.com/page2.php");
else
echo "Failed to Redirect page! Page Headers Already Sent!";
}everything in the code is fine because if I add a second text field, the form submits just the way it should and goes to the next page...but why wont it do it with just one text field? And if I DO need another field, is there any way that I can make it look like (to the client) that there is only one text field? I know that's not the best fix, but if it works, I will use it.
You can stick a hidden field into your form and check on its value after the submit. This should work:
then:
Hope, this helps
oceglok
Code: Select all
<input type="e;hidden"e; name="e;hidden"e; value="e;1"e;>Code: Select all
if (isset($_POST['hidden']) && $_POST['hidden'] == "1") {
// your redirection code here
}oceglok