473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to POST 'submit' when ENTER KEY is pressed on a FORM with only one textfield

Hi!

Here's my situation:
I have one textfield with one 'submit' button in PAGE1.PHP.

When I click on the 'submit' button I am sent to PAGE2.PHP where I have a "switch" routine that checks which 'submit' button was clicked and directs which instructions to do next.

My Problem is this:
On PAGE1.PHP, there is only one textfield. After filling in the textfield, most of the time people press the 'ENTER KEY' instead of clicking the submit button. Naturally, I am now sent to PAGE2.PHP after pressing the enter key but when I check the value of 'submit', it's empty, or not set, or not posted. So, my "switch" routine can no longer direct my program to the appropriate instructions.

Can someone please help or show me how to post the 'submit' variable when I press the enter key.

Observation:
I have observed that this behaviour only happens with one textfield on the FORM. Other FORMS with more than one textfield, treats the enter key the same way as clicking the submit button... it posts the 'submit' variable

Hope someone can help.

Learning
Sep 6 '07 #1
9 10518
ak1dnar
1,584 Expert 1GB
Could you please post the form and the php script that you have used for this. (no need to post the entire code here)
Sep 6 '07 #2
Could you please post the form and the php script that you have used for this. (no need to post the entire code here)
Hi ajaxrand.

Here's a simple version for easier understanding:

PAGE1.PHP:

Expand|Select|Wrap|Line Numbers
  1. <form action="page2.php" method="post">
  2. <input type="text "name="name" size="20"/>
  3. <input type="submit" name="submit" value="process1"/>
  4. </form>


PAGE2.PHP:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. switch ($_POST['submit']) {
  3. case 'process1':
  4. echo "processing ONE";
  5. break;
  6. case 'process2':
  7. echo "processing TWO";
  8. break;
  9. default:
  10. break;
  11. }
  12. ?>
When you execute this code, try clicking on the button. Try again and this time press enter instead of clicking the button and you'll see what I mean.

Oh and by the way, I'm using Internet Explorer as my browser.

Learning
Sep 6 '07 #3
ak1dnar
1,584 Expert 1GB
Please find out how to use the CODE tags in the correct way. Do not type or paste the code with line numbers. It will set by the text editor by default.

This will do the job for your requirement. and why are you using "switch case" for this, its simple with this.
Expand|Select|Wrap|Line Numbers
  1. <?Php
  2. if(isset($_POST['submit'])){
  3. echo $_POST['name'];
  4. }
  5. ?>
  6.  
The bad news is the html form is not submitting the text input when there is a enter key posting. but the great fire fox is doing the job on both the ways. Yet I couldn't find out a solution for the IE issue. may be some one can help you from the HTML forum.Its better to ask the question on this forum. or I can move it there since It is a HTML issue. Shall I?
Sep 6 '07 #4
Please find out how to use the CODE tags in the correct way. Do not type or paste the code with line numbers. It will set by the text editor by default.

This will do the job for your requirement. and why are you using "switch case" for this, its simple with this.
Expand|Select|Wrap|Line Numbers
  1. <?Php
  2. if(isset($_POST['submit'])){
  3. echo $_POST['name'];
  4. }
  5. ?>
  6.  
The bad news is the html form is not submitting the text input when there is a enter key posting. but the great fire fox is doing the job on both the ways. Yet I couldn't find out a solution for the IE issue. may be some one can help you from the HTML forum.Its better to ask the question on this forum. or I can move it there since It is a HTML issue. Shall I?
Hi again ajaxrand.

Yes, I kinda realize that after submitting my concern. I'll switch to HTML forum and find it out there.

And yes, I've already tried that approach instead of using the 'switch'. I may have to go back to that if I can't find out a solution to the enter key thing.

Thank you for helping me understand how to use the code tags. I never really understood that till now.

I really appreciate your taking time to share your thoughts to help me out.

Learning
Sep 6 '07 #5
ak1dnar
1,584 Expert 1GB
No problem good luck with your project.Since you have already posted another thread on the HTML/CSS forum, I am not going to move this one.
Sep 6 '07 #6
Atli
5,058 Expert 4TB
Hi.

If a form is submitted without the use of a Submit button, none of the Submit <input> tags will be included in the data that is sent.

My advice is to decide on a default course of action, if the user presses the enter key, or the form is submitted via JavaScript, then you can add the 'default' case in your switch clause and handle all such cases the same.

For example:
Expand|Select|Wrap|Line Numbers
  1. switch($_POST['mySubmit'])
  2. {
  3.   case 'btn1':
  4.     # Do stuff for btn1
  5.     break;
  6.   case 'btn2':
  7.     # Do stuff for btn2
  8.     break;
  9.   case 'btn3':
  10.     # Do stuff for btn3
  11.     break;
  12.   default:
  13.     # Do stuff if $_POST['mySubmit'] has any
  14.     # other value than the once listed above.
  15. }
  16.  
Sep 6 '07 #7
ak1dnar
1,584 Expert 1GB
Hey guys,
I have merged duplicate threads.
Sep 6 '07 #8
Hi.

If a form is submitted without the use of a Submit button, none of the Submit <input> tags will be included in the data that is sent.

My advice is to decide on a default course of action, if the user presses the enter key, or the form is submitted via JavaScript, then you can add the 'default' case in your switch clause and handle all such cases the same.

For example:
Expand|Select|Wrap|Line Numbers
  1. switch($_POST['mySubmit'])
  2. {
  3.   case 'btn1':
  4.     # Do stuff for btn1
  5.     break;
  6.   case 'btn2':
  7.     # Do stuff for btn2
  8.     break;
  9.   case 'btn3':
  10.     # Do stuff for btn3
  11.     break;
  12.   default:
  13.     # Do stuff if $_POST['mySubmit'] has any
  14.     # other value than the once listed above.
  15. }
  16.  
Hello Atli,

Yes, you're right. I will definitely used your solution. You're a genius.

Thank you. I really appreciate it.

Learning
Sep 7 '07 #9
Hey guys,
I have merged duplicate threads.

Hi Ajaxrand,

Thank you. You're all very helpful.

Learning
Sep 7 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
8
by: Syed Ali | last post by:
Hello, I have 1 HTML form with 4 submit buttons and 10 textfield entry areas. If submit button1 is pressed I need to make sure that all 10 textfield entries have been filled before submitting...
4
by: Peloux | last post by:
Hi, I have written some htc in order to validate data in a form. most of htc are attached on 'onblur' event. Now, we would like to use the Enter Key to sublit form, so we use the following...
11
by: Sandra Castellanos | last post by:
Hello, I want to know what I have to do to make the enter key to submit forms. I read in another newsgroup that inserting an html hidden text box made the trick, and it actually does, but in my...
6
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many...
19
by: darrel | last post by:
On my vb.net page, I have 4 sets of inputs + form buttons. example: Search: (GO) Zip: (GO) County: (GO) County: (GO) The problem is if I go to the page, type in a zip code, and hit...
2
by: roger31 | last post by:
Hello - I created a simple website with one page. This simple page has only one text box (asp:Textbox) and no other controls. When i bring the siteup in VS2005 and press enter with the cursor...
14
by: Robert S | last post by:
I am trying to use POST to transfer data to another page. When I do this, '.' characters get converted to"_". For example: #index.html: <form action="test.php" method="post"> <input...
6
by: Mark B | last post by:
I have a function that looks up a SQL table to see if a search term matches. It works fine but so far there are two things yet to work: 1) After entering a search term and pressing Enter, nothing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...
0
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
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...

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.