By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,856 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,856 IT Pros & Developers. It's quick & easy.

hitting enter on a form instead of clicking the button

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.