Jump to: navigation, search

PHP HTML Multiple Submit Buttons

From w3cyberlearnings

Contents

PHP works with Multiple submit buttons

Multiple submit buttons within a form is possible. Check the example for more detail.

Syntax Multiple Submit Buttons

<input type="submit" name="operation" value="add" />
<input type="submit" name="operation" value="subtract" />

Example 1

<?php
$total = 0;
if (!empty($_POST['operation']) && isset($_POST['operation'])) {
	switch ($_POST['operation']) {
		case 'add':
			$total = $_POST['number1'] + $_POST['number2'];
			break;
		case 'subtract':
			$total = $_POST['number1'] - $_POST['number2'];
			break;
	}
}
?>

<html>
<head>
<title>Multiple Submit Form</title>
</head>
<body>
<b><?php echo 'Total : ' . $total; ?></b>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="0">
<tr>
<td>Number One:</td>
<td><input type="text" name="number1" size="4" maxlength="4"/></td>
</tr>
<tr>
<td>Number Two:</td>
<td><input type="text" name="number2" size="4" maxlength="4"/></td>
</tr>
<tr>
<td colspan="2">
	<input type="submit" name="operation" value="add" />
	<input type="submit" name="operation" value="subtract" />
</td>
</tr>
</table>
</form>
</body>
</html>

Php form multiple submit 1.png


Related Links


  1. HTML POST
  2. HTML GET
  3. HTML Textarea
  1. HTML Hidden Field
  2. HiddenField Multiple Pages
  3. HTML Password
  1. HTML Textbox
  2. HTML Checkbox
  3. HTML Radio
  1. Drop down list
  2. Pass value uses URL
  3. Pass value uses URL 2.
  4. Multiple Submit Buttons
Navigation
Web
SQL
MISC
References