Re: multiple submit buttons
| From: | Matt McClanahan | Date: | Sat, 25 Nov 2000 08:59:00 +0000 |
| Subject: | Re: multiple submit buttons | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27120@lists.php.net to get a copy of this message | ||
On Sat, 25 Nov 2000, Deepak Chawla wrote:
> 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 ??
HTML does provide a way for doing this, and it worries me how many people
suggested using JavaScript, or even seperate forms to accomplish this.
First, using seperate forms is just silly. Why would that ever be a good
idea? You'd have to have two seperate text fields, which is redundant.
Second, relying on JavaScript is a very bad habit if you're interested in
your code working everywhere.
It's quite simple.
Your form:
<form method="post" action="action.php">
Filename: <input type="text" name="filename"><br><br>
<input type="submit" name="action" value="View
File"><br>
<input type="submit" name="action" value="Delete File">
</form>
The action.php:
<?
// This could also be a series of if/else if's
switch ($action)
{
case 'View File':
echo 'You chose to view the file.';
break;
case 'Delete File':
echo 'You chose to delete the file.';
break;
}
?>
Matt