473,800 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ 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("Locatio n: 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 3198
T.E. wrote:
Here's pseudocode of my php file:

<?php
if (isset($_POST['submit']))
{
if (isset($_POST['textbox']))
header("Locatio n: 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("locatio n: 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.u k> 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("locatio n: 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
9144
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 point here is that I want to read the value typed into the TextBox without hitting the Enter key or setting focus on another control ...
2
2503
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, show;hide a panel. How can i raise this method just pressing ENTER in textbox? Thanks Fernando
4
2228
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.. suddenly have a strange problem. When standing in the last cell on a row and pressing TAB och Enter the cursor move to the SECOND cell on the next row and not the first cell. Why? The only thing I have seen so far that's different in the customers
6
5278
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 characters - 'a' and '\n' (Hex 61 and 0a) It seems as though the getchar() function needs ENTER to terminate reading stdin. I am trying to get the program to respond when I press one key only (ie
3
5674
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 another way. Why? Then, another question: Is there a specific function to exit program pressing any button?
3
1137
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? Private Sub RenameToolStripMenuItem_Click(ByVal sender As
9
2970
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 enter,
1
2160
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 enter,
14
2866
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 message. may you tell me what is wrong and how to make that right ? ------------------------------ INPUT --------------------- #include <stdio.h> int main() {
18
4614
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 function, or one calls the other. Isn't there an event for 'ListBox selection selected' that is automatically called by ALL the standard GUI ways of doing it? C'mon, this is C#, we aren't supposed to be programming the GUI. There has to be such...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10251
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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 we have to send another system
3
2945
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.