Multiple Submit Buttons
- When we use more than one submits button on the form then it is called multiple submit buttons.
- It performs different tasks in a page.
Syntax: -
<input
type = “submit” name = “submit_button_name” value = “display value on the
button”>
Example: -
<INPUT
type=”SUBMIT” name=”Submit1” value=”ADD”>
<INPUT
type=”SUBMIT” name=”Submit2” value=”SUB”>
Program:-
<?php
if($_POST['submit1'] != '')
{
echo "You hit the button 1";
}
if($_POST['submit2'] != '')
{
echo "You hit the button 2";
}
?>
<html>
<head><title>Multiple Submit button Solved with PHP!</title></head>
<body>
<form action="" method="post">
<h2> Hit the Submit Button</h2>
<input type="submit" name="submit1" value="btn1" />
<input type="submit" name="submit2" value="btn2" />
</form>
</body>
</html>
Example: -
<?php
extract($_POST);
//do addition and store the result in $res
if(isset($add))
{
$res=$fnum+$snum;
}
//do subtraction and store the result in $res
if(isset($sub))
{
$res=$fnum-$snum;
}
//do multiplicatio and store the result in $res
if(isset($mult))
{
$res=$fnum*$snum;
}
?>
<html>
<head>
<title>Display the result in 3rd text box</title >
</head>
<body>
<form method="post">
<table align="center" border="1">
<Tr>
<th>Result</th>
<td><input type="text" value="<?php echo @$res;?> " readonly=""/></td>
</tr>
<tr>
<th>Enter first number</th>
<td><input type="text" name="fnum"/></td>
</tr>
<tr>
<th>Enter second number</th>
<td><input type="text" name="snum"/></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="+" name="add"/>
<input type="submit" value="-" name="sub"/>
<input type="submit" value="*" name="mult"/>
</tr>
</table>
</form>
</body>
</html>
=========================================================
0 Comments