Re: Re[2]: [PHP] Re: Form Submission
| From: | Torsten Roehr | Date: | Wed, 07 Jul 2004 18:13:32 +0000 |
| Subject: | Re: Re[2]: [PHP] Re: Form Submission | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-189894@lists.php.net to get a copy of this message | ||
"Justin Patrin" <papercrane@gmail.com> wrote in message
news:432beae0407071030c66e30a@mail.gmail.com...
> On Wed, 7 Jul 2004 10:06:25 +0200, Torsten Roehr <roehr@zilleon.com>
wrote:
> > "Curt Zirzow" <php-general@zirzow.dyndns.org> wrote in message
> > news:20040706221159.GM99175@bagend.shire...
> > > * Thus wrote Torsten Roehr:
> > > > > >
> > > > > > How do you check which button was pressed (read: which action
should
> > be
> > > > > > performed) when not relying on this?
> > > > > >
> > > > >
> > > > > The button is generally *not* sent by the browser if you hit enter
> > > > > instead of submit. This *will* happen, so you have to deal with
it.
> > > > >
> > > > > If you want to knwo what button was pressed, you have to have
> > > > > different button names or values and check them. A button is just
> > > > > another form element that is submitted.
> > > >
> > > > I believe you are wrong here. I just checked it in IE5 and Opera
7.23.
> > > > Submitting a form by hitting enter IS THE SAME as pressing a submit
> > button
> > >
> > > no, it is simply unpredictable to what will happen, my test case...
> > >
> > > Site: google.com
> > > Browsers: IE6, Opera, Firefox, netscape4
> > > Test: Enter 'asdf' and hit enter.
> > >
> > > Results:
> > > Opera and firefox sent in the url &btnG=Search, signifying that
> > > the first button has been submited.
> > >
> > > IE6 and netscape4, don't have that parameter in the url.
> > >
> > > In fact, google *had* code that checked for the btnG value and if it
> > > exsited it would display a tip about being able to simply hit
> > > enter. They no longer do that since it is unreliable.
> > >
> > > >
> > > > So from my point of view a form cannot be submitted without at least
one
> > of
> > > > the submit button values ending in POST.
> > >
> > > And if it did, which one does it send? If there are multiple
> > > buttons on a page, does it send the one closest to the focused
> > > item? or does it send the very first one it finds no matter how the
> > > page is visually layed out?
> > >
> > > >
> > > > What do you think?
> > >
> > > Never rely on button values to decide on a course of action.
> >
> > Dear Curt and Justin,
> >
> > thanks for putting so much effort into this topic. Then how do YOU
handle
> > this? How do you set up your form actions and how do you check them
> > regardless of the submit buttons?
> >
>
> To know if a form has been submitted, I generally use a hidden
> variable (usually called "submitted"). This lets me easily know if the
> form was submitted, even if it had no values in any other fields. I
> means I don't have to rely on user input or button-pushing.
>
> If you *do* have multiple buttons, you should still have the
> "submitted" hidden field, but also check the button values. If no
> button values are present, you either have to assume that the suer
> meant one of them (normal submit maybe?) or show an error and have the
> user click the right button.
>
> I've frequently used two buttons with the same name that have the
> values "yes" and "no". If the user submits the form without pressing a
> button, I assume "yes". In other words,
> if(isset($_REQUEST['submitted']) && $_REQUEST['confirm'] !=
> 'no') {
> file://process form data
> }
Thanks, Justin!