How to submit a form when user presses Enter key

How to submit a form when user presses Enter key

am 15.01.2008 20:04:47 von Daniel Klein

I'm pretty new at php and web stuff so please be gentle with me.

I'm trying to get a form to submit when the user presses the Enter
key. I do not want to use javascript. I've googled this to death and
cant find the answer (only hints), except on the 'Experts Exhange'
page and you have to pay to get the answer :-(

Why is this such a secret in the open source world we live in?

Daniel Klein

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:07:29 von Csaba

"Daniel Klein" wrote in message
news:ts0qo3p6i33dh14e9aoookeldba13g1g3h@4ax.com...
> I'm pretty new at php and web stuff so please be gentle with me.
>
> I'm trying to get a form to submit when the user presses the Enter
> key. I do not want to use javascript. I've googled this to death and
> cant find the answer (only hints), except on the 'Experts Exhange'
> page and you have to pay to get the answer :-(
>
> Why is this such a secret in the open source world we live in?
>
> Daniel Klein

Hi,
If you have a form with a submit button, then ENTER will submit the
form as far as I know.
Not sure about all OS-en or browsers BTW.

Richard.

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:17:47 von Courtney

Daniel Klein wrote:
> I'm pretty new at php and web stuff so please be gentle with me.
>
> I'm trying to get a form to submit when the user presses the Enter
> key. I do not want to use javascript. I've googled this to death and
> cant find the answer (only hints), except on the 'Experts Exhange'
> page and you have to pay to get the answer :-(
>
> Why is this such a secret in the open source world we live in?
>
> Daniel Klein

I think this is a browser specific thing.

Not sure, but some sites where the submit button don't work on firefox
or safari, will submit on safari, but not on firefox..

Sadly I suspect JavaShite is the only solution.

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:21:15 von Daniel Klein

On Tue, 15 Jan 2008 20:07:29 +0100, "Richard" wrote:

>
>"Daniel Klein" wrote in message
>news:ts0qo3p6i33dh14e9aoookeldba13g1g3h@4ax.com...
>> I'm pretty new at php and web stuff so please be gentle with me.
>>
>> I'm trying to get a form to submit when the user presses the Enter
>> key. I do not want to use javascript. I've googled this to death and
>> cant find the answer (only hints), except on the 'Experts Exhange'
>> page and you have to pay to get the answer :-(
>>
>> Why is this such a secret in the open source world we live in?
>>
>> Daniel Klein
>
>Hi,
>If you have a form with a submit button, then ENTER will submit the
>form as far as I know.
>Not sure about all OS-en or browsers BTW.

Here is a extremely simplified example:



Test Page








So there is one 'submit' button. It appears that the button has to be
in focus in order for the user to be able to submit the form with the
Enter key. What am I missing? Is this even possible?

[ And let's not start another thread on Get vs Post :-) ]

Daniel Klein

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:21:28 von Ivan Marsh

On Tue, 15 Jan 2008 20:07:29 +0100, Richard wrote:

>
> "Daniel Klein" wrote in message
> news:ts0qo3p6i33dh14e9aoookeldba13g1g3h@4ax.com...
>> I'm pretty new at php and web stuff so please be gentle with me.
>>
>> I'm trying to get a form to submit when the user presses the Enter
>> key. I do not want to use javascript. I've googled this to death and
>> cant find the answer (only hints), except on the 'Experts Exhange'
>> page and you have to pay to get the answer :-(
>>
>> Why is this such a secret in the open source world we live in?
>>
>> Daniel Klein
>
> Hi,
> If you have a form with a submit button, then ENTER will submit the
> form as far as I know.
> Not sure about all OS-en or browsers BTW.

I'd tend to agree with that... I use a function that prevents it from
doing so.

Experts Exchange is one of the sites in my blacklist... never trust a
technical site whose domain is pronounced "expert sexchange".


--
I told you this was going to happen.

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:26:17 von Daniel Klein

On Tue, 15 Jan 2008 19:17:47 +0000, The Natural Philosopher
wrote:

>Daniel Klein wrote:
>> I'm pretty new at php and web stuff so please be gentle with me.
>>
>> I'm trying to get a form to submit when the user presses the Enter
>> key. I do not want to use javascript. I've googled this to death and
>> cant find the answer (only hints), except on the 'Experts Exhange'
>> page and you have to pay to get the answer :-(
>>
>> Why is this such a secret in the open source world we live in?
>>
>> Daniel Klein
>
>I think this is a browser specific thing.
>
>Not sure, but some sites where the submit button don't work on firefox
>or safari, will submit on safari, but not on firefox..
>
>Sadly I suspect JavaShite is the only solution.

Ok, that makes sense. I have been testing on Firefox and Opera (I hate
IE). Safari uses too much memory on Windows so I am waiting for the
next release.

....and I have the same opinion as you on javascript ;-)

Daniel Klein

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:27:07 von Csaba

"Daniel Klein" wrote in message
news:g91qo3tkqqv777bd6elc5ercea91iddl7r@4ax.com...
> On Tue, 15 Jan 2008 20:07:29 +0100, "Richard"
> wrote:
>
>>
>>"Daniel Klein" wrote in message
>>news:ts0qo3p6i33dh14e9aoookeldba13g1g3h@4ax.com...
>>> I'm pretty new at php and web stuff so please be gentle with me.
>>>
>>> I'm trying to get a form to submit when the user presses the Enter
>>> key. I do not want to use javascript. I've googled this to death
>>> and
>>> cant find the answer (only hints), except on the 'Experts Exhange'
>>> page and you have to pay to get the answer :-(
>>>
>>> Why is this such a secret in the open source world we live in?
>>>
>>> Daniel Klein
>>
>>Hi,
>>If you have a form with a submit button, then ENTER will submit the
>>form as far as I know.
>>Not sure about all OS-en or browsers BTW.
>
> Here is a extremely simplified example:
>
>
>
>

Test Page


>

>
>

>
>
>
> So there is one 'submit' button. It appears that the button has to
> be
> in focus in order for the user to be able to submit the form with
> the
> Enter key. What am I missing? Is this even possible?
>
> [ And let's not start another thread on Get vs Post :-) ]
>
> Daniel Klein

I think its enough for the form to have the focus (if there is such a
thing).
If you add a text input, and type something in there, then try the
ENTER key.
What is a form without fields?
:)
Richard.

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:30:40 von axlq

In article ,
Daniel Klein wrote:
>I'm pretty new at php and web stuff so please be gentle with me.
>
>I'm trying to get a form to submit when the user presses the Enter
>key.

A browser should do this automatically on any form that contains a
text input field . If you press Enter after
typing something in the field, the form should submit. Nearly all
browsers I have used do this.

I don't know why you'd want it on forms without a text input field,
even with Javascript. As a user, *I* certainly don't want to be
submitting a form if I happen to press the Enter key.

>Why is this such a secret in the open source world we live in?

It's no secret. It's built into the browser.

-A

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:32:37 von ivansanchez-alg

Daniel Klein wrote:

> What am I missing?

A text field.

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

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:35:17 von Daniel Klein

On Tue, 15 Jan 2008 19:30:40 +0000 (UTC), axlq@spamcop.net (axlq)
wrote:

>In article ,
>Daniel Klein wrote:
>>I'm pretty new at php and web stuff so please be gentle with me.
>>
>>I'm trying to get a form to submit when the user presses the Enter
>>key.
>
>A browser should do this automatically on any form that contains a
>text input field . If you press Enter after
>typing something in the field, the form should submit. Nearly all
>browsers I have used do this.
>
>I don't know why you'd want it on forms without a text input field,
>even with Javascript. As a user, *I* certainly don't want to be
>submitting a form if I happen to press the Enter key.
>
>>Why is this such a secret in the open source world we live in?
>
>It's no secret. It's built into the browser.

I agree, but the problem is a little deeper than that. What if there
are 2 (or more) submit buttons. What html needs to be there to
indicate the 'default' button?

Daniel Klein

Re: How to submit a form when user presses Enter key

am 15.01.2008 20:55:47 von Chuck Anderson

Daniel Klein wrote:
> On Tue, 15 Jan 2008 19:30:40 +0000 (UTC), axlq@spamcop.net (axlq)
> wrote:
>
>
>> In article ,
>> Daniel Klein wrote:
>>
>>> I'm pretty new at php and web stuff so please be gentle with me.
>>>
>>> I'm trying to get a form to submit when the user presses the Enter
>>> key.
>>>
>> A browser should do this automatically on any form that contains a
>> text input field . If you press Enter after
>> typing something in the field, the form should submit. Nearly all
>> browsers I have used do this.
>>
>> I don't know why you'd want it on forms without a text input field,
>> even with Javascript. As a user, *I* certainly don't want to be
>> submitting a form if I happen to press the Enter key.
>>
>>
>>> Why is this such a secret in the open source world we live in?
>>>
>> It's no secret. It's built into the browser.
>>
>
> I agree, but the problem is a little deeper than that. What if there
> are 2 (or more) submit buttons. What html needs to be there to
> indicate the 'default' button?
>
> Daniel Klein
>

First off .... It's IE that does not submit with Enter. Firefox does.

As far as I know there is no way to "indicate" the default button. If
there are two submit buttons, the first is submitted (by Firefox).

In that case, if necessary, I use JavaScript on text fields to disable
Enter from submitting.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************

Re: How to submit a form when user presses Enter key

am 16.01.2008 00:34:58 von Logos

On Jan 15, 12:04 pm, Daniel Klein wrote:
> I'm pretty new at php and web stuff so please be gentle with me.
>
> I'm trying to get a form to submit when the user presses the Enter
> key. I do not want to use javascript. I've googled this to death and
> cant find the answer (only hints), except on the 'Experts Exhange'
> page and you have to pay to get the answer :-(
>
> Why is this such a secret in the open source world we live in?
>
> Daniel Klein

If I remember correctly, enter as a submit button trigger only works
if the form has only 1 element besides a submit button (ie, a single
text field) or javascript using a keylistener.

As for Experts Exchange, it's pretty much an open secret that if you
use google and get an EE result, all you need do is click the cached
link and the answers will be visible :)

Re: How to submit a form when user presses Enter key

am 16.01.2008 00:42:38 von luiheidsgoeroe

On Tue, 15 Jan 2008 20:35:17 +0100, Daniel Klein =

wrote:

> On Tue, 15 Jan 2008 19:30:40 +0000 (UTC), axlq@spamcop.net (axlq)
> wrote:
>
>> In article ,
>> Daniel Klein wrote:
>>> I'm pretty new at php and web stuff so please be gentle with me.
>>>
>>> I'm trying to get a form to submit when the user presses the Enter
>>> key.
>>
>> A browser should do this automatically on any form that contains a
>> text input field . If you press Enter after
>> typing something in the field, the form should submit. Nearly all
>> browsers I have used do this.
>>
>> I don't know why you'd want it on forms without a text input field,
>> even with Javascript. As a user, *I* certainly don't want to be
>> submitting a form if I happen to press the Enter key.
>>
>>> Why is this such a secret in the open source world we live in?
>>
>> It's no secret. It's built into the browser.
>
> I agree, but the problem is a little deeper than that. What if there
> are 2 (or more) submit buttons. What html needs to be there to
> indicate the 'default' button?

An hidden input, with default value? Firefox and some others will indeed=
=

use the first submit button they encounter, for others the hidden input =
=

can tell you what to do. It requires some extra care, and if you've only=
=

one script processing only one particular form, this is offcourse not =

needed, as you can have your default defined in PHP. However, if you hav=
e =

some more complicated framework hidden inputs can help you a lot:

Form:




(By the way, offcourse you can use the values of submit buttons instead =
of =

using a pseudo array, but normally I'd like a little more freedom in =

those, as they're displayed text. They may be translated, or altered on =
a =

request of a client. This way the underlying logic would remain the same=
).

Script:
$actions =3D array();
if(isset($_POST['action']) && is_array($_POST['action'])){
$actions =3D array_keys($_POST['action']);
} else if(isset($_POST['defaultaction'])){
$actions =3D array($_POST['defaultaction']);
} else {
//no action given, depends on your design what to do.
}
foreach($actions as $action){
switch($action){
case 'edit':
//code
break;
case 'edit':
//code
break;
default:
//unknown action, decide how to handle this
}
}
?>

This example would be of a framework that is able to handle different =

requests in one go BTW, if you need to have only one action valid, it =

could easily be altered to fit that. If you do use the values of a submi=
t =

button, and only one action is legal, the fact that later input with the=
=

same name overwrite the previous one will help you:



....some other non-submit inputs




And independently of UA, if the form is submitted by enter 'edit' will =

always be chosen.
-- =

Rik Wasmus

Re: How to submit a form when user presses Enter key

am 16.01.2008 04:18:26 von Daniel Ennis

The Natural Philosopher wrote:
> Daniel Klein wrote:
>> I'm pretty new at php and web stuff so please be gentle with me.
>>
>> I'm trying to get a form to submit when the user presses the Enter
>> key. I do not want to use javascript. I've googled this to death and
>> cant find the answer (only hints), except on the 'Experts Exhange'
>> page and you have to pay to get the answer :-(
>>
>> Why is this such a secret in the open source world we live in?
>>
>> Daniel Klein
>
> I think this is a browser specific thing.
>
> Not sure, but some sites where the submit button don't work on firefox
> or safari, will submit on safari, but not on firefox..
>
> Sadly I suspect JavaShite is the only solution.
>
>
>
>

By the way, Experts Exchange is pretty silly. If you found the Experts
Exchange by Google, just click the 'Cache' link and you will see the
answers without having to pay :)

--
Daniel Ennis
faNetworks.net - Quality Web Hosting and Ventrilo Services
System Administrator / Web Developer
PHP Developer for 6 years
daniel@fanetworks.net

Re: How to submit a form when user presses Enter key

am 16.01.2008 15:53:28 von radmission05

On Jan 15, 11:04 am, Daniel Klein wrote:
> I'm pretty new at php and web stuff so please be gentle with me.
>
> I'm trying to get a form to submit when the user presses the Enter
> key. I do not want to use javascript. I've googled this to death and
> cant find the answer (only hints), except on the 'Experts Exhange'
> page and you have to pay to get the answer :-(
>
> Why is this such a secret in the open source world we live in?
>
> Daniel Klein

check this






onkeydown="submit_form('myform')">

Re: How to submit a form when user presses Enter key

am 16.01.2008 15:55:09 von radmission05

On Jan 15, 11:04 am, Daniel Klein wrote:
> I'm pretty new at php and web stuff so please be gentle with me.
>
> I'm trying to get a form to submit when the user presses the Enter
> key. I do not want to use javascript. I've googled this to death and
> cant find the answer (only hints), except on the 'Experts Exhange'
> page and you have to pay to get the answer :-(
>
> Why is this such a secret in the open source world we live in?
>
> Daniel Klein

remember key 13, is keyboard key for Enter/ Carriage return.

Re: How to submit a form when user presses Enter key

am 18.01.2008 12:52:48 von Bob

radmission05@gmail.com ha scritto:
> On Jan 15, 11:04 am, Daniel Klein wrote:
>> I'm pretty new at php and web stuff so please be gentle with me.
>>
>> I'm trying to get a form to submit when the user presses the Enter
>> key. I do not want to use javascript. I've googled this to death and
>> cant find the answer (only hints), except on the 'Experts Exhange'
>> page and you have to pay to get the answer :-(
>>
>> Why is this such a secret in the open source world we live in?
>>
>> Daniel Klein
>
> check this
>
>
>
>
>


>
> > onkeydown="submit_form('myform')">
>
>


This is HTML!
Whenever you type the ENTER key on a single field you achieve a
SUBMIT as long as: a) the form has only that field; *or* b) the form has
an on it.

have fun!