473,480 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with pressing enter on one-textfield form

Hi all,

I'm a newbie in php.

I encounter a problem with php form that has only one textfield.

If I click on the submit button, the form works fine. However, when I
press 'enter', the form doesn't work right.

After comparing that form with other forms, I noticed the problem
happens because I only have one textfield and a submit button in the
form.
If I add another textfield, I can hit 'enter' to submit the form;
however, that's not a good solution.

Has anyone encountered this problem before, and what's the best
solution?

Here's pseudocode of my php file:

<?php
if (isset($_POST['submit']))
{
if (isset($_POST['textbox']))
header("Location: otherpage.php"); //redirect to other page
}
?>
//else stay on the form page
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Please enter something in the textbox
<input type="text" name="textbox" size="20">
<input type="submit" value="Submit" name="submit">
</form>

Does anyone have the right solution for this problem?
FYI, I use php 4.3.3 and I test it on IE 6.0.

I really appreciate your help and thx in advance.

Regards,
Tony
Jul 17 '05 #1
2 3173
T.E. wrote:
Here's pseudocode of my php file:

<?php
if (isset($_POST['submit']))
{
if (isset($_POST['textbox']))
header("Location: otherpage.php"); //redirect to other page
}
?>
//else stay on the form page
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Please enter something in the textbox
<input type="text" name="textbox" size="20">
<input type="submit" value="Submit" name="submit">
</form>

Hello, I would be happy to help :)

I guess it does not work when you press enter because the submit button
variable is not being sent with the form (right?). To counter this use
the code below:

You have to remove the if(isset($_POST['BUTTONNAME'])){ }

<?php
if (isset($_POST['textbox'])){
/* redirects to other page and exits */
header("location: otherpage.php");
exit;
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Please enter something in the textbox
<input type="text" name="textbox" size="20" />
<input type="submit" name="submit" value="Submit" />
</form>
NOTE: I added an exit command after the header is sent. Not having this
is a severe security issue, since the server will execute all the code
below even if the client has been directed somewhere else.

Hope I helped ;).
Jul 17 '05 #2
Thanks MJaC for your input.

I think I also need to check if textbox is empty, because
isset(textbox) returns 'true' when my cursor is inside the box as I
hit enter (even though the textbox is empty).

And thanks as well for the 'exit()' reminder ;)

T.E.
MJaC <mj**@mjac.co.uk> wrote in message news:<40**************@mjac.co.uk>...
Hello, I would be happy to help :)

I guess it does not work when you press enter because the submit button
variable is not being sent with the form (right?). To counter this use
the code below:

You have to remove the if(isset($_POST['BUTTONNAME'])){ }

<?php
if (isset($_POST['textbox'])){
/* redirects to other page and exits */
header("location: otherpage.php");
exit;
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Please enter something in the textbox
<input type="text" name="textbox" size="20" />
<input type="submit" name="submit" value="Submit" />
</form>
NOTE: I added an exit command after the header is sent. Not having this
is a severe security issue, since the server will execute all the code
below even if the client has been directed somewhere else.

Hope I helped ;).

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
9113
by: mg | last post by:
I want to enter characters in a TextBox in a WebForm, press a Button in the WebForm, and read the characters that were typed into the TextBox from within the Button_Click event handler. The main...
2
2484
by: Fernando Lopes | last post by:
Hi. I one usercontrol, i have a zipcode textbox . I need to, when user press ENTER, I call a code-behind method, to check this zipcode on database and, depending the return of this check,...
4
2203
by: Lars Netzel | last post by:
Hello! I have made my application move to the next cell on TAB and Enter and it works fine for me and all the other computer I 've tested on in the office. When deploying at the customer.....
6
5251
by: Alan | last post by:
I am using Standard C compiled with GCC under Linux Fedora Core 4 When I run this program and enter a character at the prompt, I have to press the ENTER key as well. This gives me 2 input...
3
5662
by: MargNat | last post by:
Hi, I've wrote a simple c++ program without graphic interface; Now, if I build it with Visual Studio function getchar() works in a way; if I build it with Dev-C++ function getchar() works in...
3
1124
by: Marc | last post by:
Guys, I have a text box. I simply want to save the text from the text box (and popluate a buttons text) and remove the text box when a user hits the enter button. Can someone help? ...
9
2942
by: Camellia | last post by:
Hi all, I'll get straight into it. When I try to run the code: ..... while (scanf("%c", &c) == 1) printf("%c", c); ..... I input "abcd" follows by an EOF(Ctrl + d) instead of pressing...
1
2137
by: Camellia | last post by:
Hi all, I'll get straight into it. When I try to run the code: ..... while (scanf("%c", &c) == 1) printf("%c", c); ..... I input "abcd" follows by an EOF(Ctrl + d) instead of pressing...
14
2836
by: arnuld | last post by:
i have slightly modified the programme from section 1.5.1 which takes the input frm keyboard and then prints that to the terminal. it just does not run and i am unable to understand the error...
18
4579
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.