Connecting Tech Pros Worldwide Forums | Help | Site Map

Anyone know why this is happening?

Bosconian
Guest
 
Posts: n/a
#1: Jul 17 '05
This is more of an HTML question, but it's related to a PHP project.

I have a simple form consisting of 2 selects, 1 text input and a submit
button. The form action submits to the same page.

When entering a string into the text input and hitting return (without
tabbing to and clicking "Submit") the page reloads, but no results appear.
However tabbing to or clicking "Submit" work as expected.

On the server side $_POST['Submit'] exists when tabbing to or clicking
"Submit", but doesn't when hitting return from the text input.

Can someone tell me why this is happening?

Thanks!



Daniel Tryba
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Anyone know why this is happening?


Bosconian <bosconian@planetx.com> wrote:[color=blue]
> When entering a string into the text input and hitting return (without
> tabbing to and clicking "Submit") the page reloads, but no results appear.
> However tabbing to or clicking "Submit" work as expected.
>
> On the server side $_POST['Submit'] exists when tabbing to or clicking
> "Submit", but doesn't when hitting return from the text input.
>
> Can someone tell me why this is happening?[/color]

-Hitting enter in a form with 1 text input firing a submit event is by
design.
-Not getting results sounds like a logic error in your code... now you know
this can happen, you know not to depend on an index in _POST called
'Submit'.

--

Daniel Tryba

Bosconian
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Anyone know why this is happening?


Dan,

Thanks for your reply.

I have changed my logic to look for one of the form fields instead of
"Submit". I'd still like to know why a submit input when given a name (i.e.
"Submit") doesn't pass when pressing enter on another form field.

"Daniel Tryba" <news_comp.lang.php@canopus.nl> wrote in message
news:cj094p$bdd$1@news.tue.nl...[color=blue]
> Bosconian <bosconian@planetx.com> wrote:[color=green]
> > When entering a string into the text input and hitting return (without
> > tabbing to and clicking "Submit") the page reloads, but no results[/color][/color]
appear.[color=blue][color=green]
> > However tabbing to or clicking "Submit" work as expected.
> >
> > On the server side $_POST['Submit'] exists when tabbing to or clicking
> > "Submit", but doesn't when hitting return from the text input.
> >
> > Can someone tell me why this is happening?[/color]
>
> -Hitting enter in a form with 1 text input firing a submit event is by
> design.
> -Not getting results sounds like a logic error in your code... now you[/color]
know[color=blue]
> this can happen, you know not to depend on an index in _POST called
> 'Submit'.
>
> --
>
> Daniel Tryba
>[/color]


Simon Stienen
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Anyone know why this is happening?


Bosconian <bosconian@planetx.com> wrote:[color=blue]
> Dan,
>
> Thanks for your reply.
>
> I have changed my logic to look for one of the form fields instead of
> "Submit". I'd still like to know why a submit input when given a name (i.e.
> "Submit") doesn't pass when pressing enter on another form field.
>
> "Daniel Tryba" <news_comp.lang.php@canopus.nl> wrote in message
> news:cj094p$bdd$1@news.tue.nl...[color=green]
>> Bosconian <bosconian@planetx.com> wrote:[color=darkred]
>>> When entering a string into the text input and hitting return (without
>>> tabbing to and clicking "Submit") the page reloads, but no results[/color][/color]
> appear.[color=green][color=darkred]
>>> However tabbing to or clicking "Submit" work as expected.
>>>
>>> On the server side $_POST['Submit'] exists when tabbing to or clicking
>>> "Submit", but doesn't when hitting return from the text input.
>>>
>>> Can someone tell me why this is happening?[/color]
>>
>> -Hitting enter in a form with 1 text input firing a submit event is by
>> design.
>> -Not getting results sounds like a logic error in your code... now you[/color]
> know[color=green]
>> this can happen, you know not to depend on an index in _POST called
>> 'Submit'.
>>
>> --
>>
>> Daniel Tryba
>>[/color][/color]

Submit-fields are only submitted in case the user clicked on them to submit
the form. Otherwise, the name-attribute would be senseless for them because
you could use hidden to archive that goal, too.
Btw: This behaviour is often used in applications, for example all bulletin
boards written in PHP I know offer an optional preview of the posting which
is about to be published. This is determined by specifiing two submit
buttons with different names and checking, which one has been used to
submit the form.
If -on the other hand- a submit button would *always* be transmitted, you
would always get both buttons and therefore be unable to determine, which
one the user clicked.
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Bosconian
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Anyone know why this is happening?


Simon,

Thanks for the clarification. I have used multiple submit buttons in a form
before for the purpose you described, but for some reason the behavior in
question was never obvious to me until now.

Regards,

"Simon Stienen" <simon.stienen@news.slashlife.de> wrote in message
news:ywm99077jgai$.dlg@news.dangerouscat.net...[color=blue]
> Bosconian <bosconian@planetx.com> wrote:[color=green]
> > Dan,
> >
> > Thanks for your reply.
> >
> > I have changed my logic to look for one of the form fields instead of
> > "Submit". I'd still like to know why a submit input when given a name[/color][/color]
(i.e.[color=blue][color=green]
> > "Submit") doesn't pass when pressing enter on another form field.
> >
> > "Daniel Tryba" <news_comp.lang.php@canopus.nl> wrote in message
> > news:cj094p$bdd$1@news.tue.nl...[color=darkred]
> >> Bosconian <bosconian@planetx.com> wrote:
> >>> When entering a string into the text input and hitting return (without
> >>> tabbing to and clicking "Submit") the page reloads, but no results[/color]
> > appear.[color=darkred]
> >>> However tabbing to or clicking "Submit" work as expected.
> >>>
> >>> On the server side $_POST['Submit'] exists when tabbing to or clicking
> >>> "Submit", but doesn't when hitting return from the text input.
> >>>
> >>> Can someone tell me why this is happening?
> >>
> >> -Hitting enter in a form with 1 text input firing a submit event is by
> >> design.
> >> -Not getting results sounds like a logic error in your code... now you[/color]
> > know[color=darkred]
> >> this can happen, you know not to depend on an index in _POST called
> >> 'Submit'.
> >>
> >> --
> >>
> >> Daniel Tryba
> >>[/color][/color]
>
> Submit-fields are only submitted in case the user clicked on them to[/color]
submit[color=blue]
> the form. Otherwise, the name-attribute would be senseless for them[/color]
because[color=blue]
> you could use hidden to archive that goal, too.
> Btw: This behaviour is often used in applications, for example all[/color]
bulletin[color=blue]
> boards written in PHP I know offer an optional preview of the posting[/color]
which[color=blue]
> is about to be published. This is determined by specifiing two submit
> buttons with different names and checking, which one has been used to
> submit the form.
> If -on the other hand- a submit button would *always* be transmitted, you
> would always get both buttons and therefore be unable to determine, which
> one the user clicked.
> --
> Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
> »What you do in this world is a matter of no consequence,
> The question is, what can you make people believe that you have done.«
> -- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle[/color]


Closed Thread