Re: HTLM forms and PHP
| From: | Matt McClanahan | Date: | Tue, 30 May 2000 20:26:07 +0000 |
| Subject: | Re: HTLM forms and PHP | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-108@lists.php.net to get a copy of this message | ||
On Tue, 30 May 2000, Ryan Patrick wrote:
> HI I have a HTML form that's basically a Customer Information Screen. I
> want it to be both an Input screen and also double as a Search Screen. IE) I
> have a Save and Find buttons where you would type in information and Either
> do a FIND for the Customer Information or Save the Customer Information as a
> New record. I was wondering if anyone can help me?? Either HTML wise or PHP
> wise. I have the Find working fine. I can't figure out how to get the Save
> button to preform the SAVE option. The Save button does the same as the
> Find.
This is probably a question best directed at the php-general list, for
future reference.
Handling multiple submit buttons in a form with PHP is fairly
straightforward. Give them all the same name, e.g,
<input type=submit name=task>
and in the script that handles the form data, check what the value of
$task is. For example, this script lets you pick a number, and do one of
three operations on that number.
<?php
if( empty($task) )
{ ?>
<form method="post" action="<? echo $PHP_SELF ?>">
<input type="radio" name="number" value=1> One <br>
<input type="radio" name="number" value=3> Three <br>
<input type="radio" name="number" value=5> Five <br>
<input type="submit" name="task" value="Double Number">
<br>
<input type="submit" name="task" value="Tripple Number">
<br>
<input type="submit" name="task" value="Quad Number">
<?
}
else
{
echo 'Action to take was: ' . $task;
echo '<br>Result is: ';
switch( $task )
{
case 'Double Number':
echo $number * 2;
break;
case 'Tripple Number':
echo $number * 3;
break;
case 'Quad Number':
echo $number * 4;
break;
}
}
?>
This is fairly simplistic, but your question follows the same concept.
You'll want to check which submit button was clicked, and deal with the
form values in the appropriate manner (Add, Search for, Update, etc)
Matt