Re: multiple submit buttons
| From: | Sebastian Delmont | Date: | Tue, 28 Nov 2000 13:37:10 +0000 |
| Subject: | Re: multiple submit buttons | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27594@lists.php.net to get a copy of this message | ||
Give each submit button a different NAME attribute...
<INPUT TYPE=SUBMIT NAME='ButtonA' VALUE='This is Button A'>
<INPUT TYPE=SUBMIT NAME='ButtonB' VALUE='This is Button B'>
in your PHP code check for the $ButtonA and B variables...
if( isset( $HTTP_POST_VARS[ "ButtonA" ] )) {
# Do Operation A
}
elseif( isset( $HTTP_POST_VARS[ "ButtonB" ] )) {
# Do Operation B
}
else {
# Do default operation
}
Using the HTTP_POST_VARS array is a good idea, since you can be sure the
parameter came via the POST, and not on the URL or defined by some code
executed previously.
You can do the same with TYPE=IMAGE buttons... but the variable name will be
ButtonA_X (and _Y).
Also... using image buttons has a small problem... When you press [enter]
inside a field, the browser usually submits the form, and it assumes you
pressed the first SUBMIT button available... since image buttons are not
exactly submit buttons (even if they submit the form when pressed), the
browser will not send any "ButtonA" variables... that's why I added the
"default" case in the sample code.
If your two buttons will be used in separated FORM blocks, you can include a
TYPE=HIDDEN field with some constant value like <INPUT TYPE=HIDDEN
NAME='Operation' VALUE='A'> that will be sent on every submit.
"Tim Parkin" <Tim.Parkin@didio.com> wrote in message
news:213127B754FBD311A02900B0D021B6C60FC968@BOS...
> you can use image buttons and check the name of the variables returned..
>
> ie images_name_x and image_name_y
>
> to see which one was pressed
>
> -----Original Message-----
> From: Deepak Chawla [mailto:dchawla@usa.unl.edu]
> Sent: Saturday, November 25, 2000 07:39
> To: php-general@lists.php.net
> Subject: [PHP] multiple submit buttons
>
>
> Hi all,
>
> I need two submit buttons in a html form, and i need them to do two
> different things...eg: a text box for a filename and two submit buttons,
> one for opening the file and another for deleting it. Since both require
> the filename field.. both have to be submit buttons.
> html in itself doesn't provide means for doing this... is there any way
> to do it ??
>
> regards
> -deepak
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>