473,403 Members | 2,270 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,403 software developers and data experts.

hitting enter on a form instead of clicking the button

I'm getting incorrect response when hitting the enter key instead of
actually clicking the button on a form. It activates but the post data
[value='Update'] isn't being sent I think. The php generated page
flickers & reloads but doesn't perform the update.

This is php generated, I'm just pasting the page source (reformatted &
extra junk removed and I think they are now identical), and it's running
on my localhost apache server for testing so maybe there's something
funny with my setup. Crossposted to html & php groups.
Must click button (no enter):

<form action='?SC=cart.php' method='POST'>
<tr>
<td>
<input type='hidden' name='item' value='6077'>name
</td>
<td>
<input type='submit' name='buy' value='Update'>
</td>
<td>
<input type='text' name='item_qty' size='1' value='2'>
</td>
</tr>
</form>
Enter or click works fine:

<form action='?SC=cart.php' method='POST'>
<tr>
<td>
<input type='hidden' name='item' value='6540'>name
</td>
<td>
<input type='submit' name='buy' value='Update'>
</td>
<td>
<input type='text' name='item_qty' size='1' value='2'>
</td>
</tr>
</form>

Here they are without me fixing up the formatting:

Must click button (no enter):

<form action='?SC=cart.php' method='POST'><tr>
<td><input type='hidden' name='item' value='6540'>Adiantum jordanii / -
1 gal</td>
<td><input type='submit' name='buy' value='Update'></td>
<td><input type='text' name='item_qty' size='1' value='1'></td>
<td>$&nbsp;9.00 </td><td>$&nbsp;9.00 </td><td>0%</td>
<td>10%</td>
</tr></form>
Enter or click works fine:

<form action='?SC=cart.php' method='POST'><tr>
<td><input type='hidden' name='item' value='6077'>Adiantum jordanii / -
1 gal</td>
<td><input type='submit' name='buy' value='Update'></td>
<td><input type='text' name='item_qty' size='1' value='2'></td>
<td>$&nbsp;10.00 </td><td>$&nbsp;20.00 </td></tr></form>
<tr><th colspan='4' align='right'>Tax:</td><td>$
1.70</td><td>&nbsp;</td></tr>
<tr><th colspan='4' align='right'>Delivery:</td><td>$
0.00</td><td>&nbsp;</td></tr>
<tr><th colspan='4' align='right'>Order Total:</th><th>$&nbsp;21.70</th>
<th><form action='?SC=checkout.php' method='post'><input type='submit'
name='checkout' value='Checkout'></form>
Mar 15 '07 #1
6 4905
Paul Furman wrote:
I'm getting incorrect response when hitting the enter key instead of
actually clicking the button on a form. It activates but the post data
[value='Update'] isn't being sent I think. The php generated page
flickers & reloads but doesn't perform the update.
That's the way it works - The name/value pair of a submit button only gets
submitted if the button is actualy pressed.

If you want to have some data every time a form is submitted, rely on <input
type='hidden'/fields.

(Check the W3.org HTML reference for more details).

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

In Marseilles they make half the toilet soap we consume in America, but
the Marseillaise only have a vague theoretical idea of its use, which they
have obtained from books of travel.
-- Mark Twain

Mar 15 '07 #2
Iván Sánchez Ortega wrote:
Paul Furman wrote:

>>I'm getting incorrect response when hitting the enter key instead of
actually clicking the button on a form. It activates but the post data
[value='Update'] isn't being sent I think. The php generated page
flickers & reloads but doesn't perform the update.


That's the way it works - The name/value pair of a submit button only gets
submitted if the button is actualy pressed.

If you want to have some data every time a form is submitted, rely on <input
type='hidden'/fields.

(Check the W3.org HTML reference for more details).
I'm not sure why it worked before in the one case but THANKS!

I added:
<input type='hidden' name='buy' value='Update'>

on top of the old:
<input type='submit' name='buy' value='whatever'>

and it works!

The test is simply:
if (isset($_REQUEST["buy"])) {
Mar 15 '07 #3
Scripsit Paul Furman:
I'm getting incorrect response when hitting the enter key instead of
actually clicking the button on a form.
Define "incorrect". The snippet of HTML that you posted is syntactically
malformed. There is no specification that says what should happen then.
It activates but the post data
[value='Update'] isn't being sent I think.
It probably isn't. This has been left to browsers, but they generally don't
treat a submit button as "successful" if it isn't used, which is rather
reasonable if you ask me.
This is php generated, I'm just pasting the page source (reformatted &
extra junk removed and I think they are now identical), and it's
running on my localhost apache server for testing so maybe there's
something funny with my setup.
As usual, you should have constructed a static HTML page that demonstrates
the problem and posted its URL.
Crossposted to html & php groups.
As usual, crossposting resulted from insufficient thinking. There is really
no reason to suspect that PHP is involved in the submission problem. You
would have seen this if you had constructed the static page. (Followups
trimmed.)
Must click button (no enter):
Huh?
<form action='?SC=cart.php' method='POST'>
<tr>
<td>
<input type='hidden' name='item' value='6077'>name
</td>
<td>
<input type='submit' name='buy' value='Update'>
</td>
<td>
<input type='text' name='item_qty' size='1' value='2'>
</td>
</tr>
</form>
This is syntactically malformed: you cannot have a <trelement as a child
of <form>.

And why do you say "no enter"? I can submit it by pressing enter if I want.

So what is your question? It's probably something closely related to some
questions in the FAQ, which you apparently didn't check before posting.

If you want to have a field always appearing in the form data (why?), then
it should be included as a hidden field _only_, preferably _without_ another
field with the same name in the same form, since it sounds like your form
handler is simplistic and could get confused with that.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Mar 16 '07 #4
Jukka K. Korpela wrote:
Scripsit Paul Furman:
>It activates but the post data
[value='Update'] isn't being sent I think.


It probably isn't. This has been left to browsers, but they generally
don't treat a submit button as "successful" if it isn't used, which is
rather reasonable if you ask me.
But below you say using the enter key should work, that was the problem,
it doesn't work.

As usual, you should have constructed a static HTML page that
demonstrates the problem and posted its URL.
>
>Crossposted to html & php groups.

I think it was pretty damned simple.

As usual, crossposting resulted from insufficient thinking. There is
really no reason to suspect that PHP is involved in the submission
problem. You would have seen this if you had constructed the static
page. (Followups trimmed.)
Who knows? Mysterious things happen. I didn't know what the problem was.

><form action='?SC=cart.php' method='POST'>
<tr>
<td>
<input type='hidden' name='item' value='6077'>name
</td>
<td>
<input type='submit' name='buy' value='Update'>
</td>
<td>
<input type='text' name='item_qty' size='1' value='2'>
</td>
</tr>
</form>

This is syntactically malformed: you cannot have a <trelement as a
child of <form>.
Obviously this is a snippet and there is a <tablestructure above this
snippet.

And why do you say "no enter"? I can submit it by pressing enter if I
want.
No, that was the problem, it doesn't pass:
if (isset($_REQUEST["buy"]))
when using the enter key, only when clicking the button.
I should have included the if clause in my OP.

So what is your question? It's probably something closely related to
some questions in the FAQ, which you apparently didn't check before posting.
What FAQ?

If you want to have a field always appearing in the form data (why?),
then it should be included as a hidden field _only_, preferably
_without_ another field with the same name in the same form, since it
sounds like your form handler is simplistic and could get confused with
that.
Yes, this was the problem.
Mar 17 '07 #5
Rik
I doubt M. Korpela will ever see this. You removed the crossposting, and
he's an alt.html visitor. I don't think he ever comes here.

--
Rik Wasmus
Mar 17 '07 #6
Rik wrote:
I doubt M. Korpela will ever see this. You removed the crossposting,
and he's an alt.html visitor. I don't think he ever comes here.
I realized that after sending & resent a copy there too :-)
Mar 17 '07 #7

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

Similar topics

1
by: ritelman | last post by:
Hi I have one text field and one submit button. If I hit the submit button with a mouse the key/value pair key are properly submitted. However, if I just hit the enter key the page does get...
10
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
3
by: Jose Egea | last post by:
Hello: I'm trying to execute a function when the user press Enter key in a TextBox. But something is happening in my form because after pressing a button, when I press the Enter key in the...
2
by: Cindy | last post by:
Hi all you smarties out there, I'm having a little conundrum with my asp.net page Scenario: I have a form (asp.net) with no code behind (as yet). I have placed a javascript function on a...
5
by: Eric | last post by:
Hi All, I'm very experienced in traditional ASP and am new to (am learning) ASP.NET. FYI: I am initially learning ASP.NET with VB.NET to ease the transition for me. I have encountered what I...
2
by: 23s | last post by:
My site's login page has a form w/ 2 textboxes and a submit button. If I'm in either of those textboxes (i.e., either one of the textboxes has focus), in any given browser, hitting "enter" on my...
3
by: PJ6 | last post by:
I want to be able to, depending on the state of the page, direct what the ENTER key causes the page to do. The problem I'm having is I have a user control with a textbox and an "enter" button....
24
by: MichaelK | last post by:
Who knows how to prevent submitting a form on the press Enter button before all fields on the form are filled up. People just enter the first field hit Enter and it submits the form and doing...
9
by: learning | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
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.