Because of the checkbox specificity, so we have to get its value, in my language is not the same, in the PHP tutorial we are in the form of an array, and the use of traversing his value, there are a number of examples below.
<title>checkbox demo</title>
<body>
<form action = "handleformcheckbox.php" >
<ul>
<li><input type = "checkbox" name = "Chkfries" value = "11.00" >fries</li>
<li><input type = "checkbox" name = "Chksoda" value = "12.85" >soda</li>
<li><input type = "checkbox" name = "Chkshake" value = "1.30" >shake</li>
<li><input type = "checkbox" name = "Chkketchup" value = ". >ketchup</li>"
</ul>
<input type = "Submit" >
</form>
</body>
<!--handleformcheckbox.php
<title>checkbox demo</title>
<body>
?
Print <<Chkfries: $chkfries <br>
Chksoda: $chksoda <br>
Chkshake: $chkshake <br>
Chkketchup: $chkketchup <br>
Here
$total = 0;
if (!empty ($chkfries)) {
Print ("You chose Fries <br>");
$total = $total + $chkfries;
}
if (!empty ($chksoda)) {
Print ("You chose Soda <br>");
$total = $total + $chksoda;
}
if (!empty ($chkshake)) {
Print ("You chose Shake <br>");
$total = $total + $chkshake;
}
if (!empty ($chkketchup)) {
Print ("You chose Ketchup <br>");
$total = $total + $chkketchup;
}
Print "The total cost is $ $total";
?>
</body>
-->
Instance
<title>using Default checkbox values</title>
<body>
<?php
$food = $_get[food];
$self = htmlentities ($_server[' php_self '));
if (!empty ($food)) {
echo "The foods selected Are:<br/>";
foreach ($food as $foodstuf)
{
echo "<strong>". Htmlentities ($foodstuf). " </strong><br/> ";
}
}
Else
{
Echo ("<form action=" "$self");
Echo (' method= ' get ' >
<fieldset>
<label>italian <input type= "checkbox" Name= "food[" value= "Italian"/>
</label>
<label>mexican <input type= "checkbox" Name= "food[" value= "Mexican"/>
</label>
<label>chinese <input type= "checkbox" Name= "food[" value= "Chinese"
Checked= "Checked"/></label>
</fieldset>
<input type= "Submit" value= "go!");
}
?>
</body>
Multiple Select checkbox
<?php
$options = Array (' option 1 ', ' option 2 ', ' option 3 ');
$valid = true;
if (Is_array ($_get[' input ')) {
$valid = true;
foreach ($_get[' input '] as $input) {
if (!in_array ($input, $options)) {
$valid = false;
}
}
if ($valid) {
Process input
}
}
?>
Instance checkbox multi-value Fetch
<title>using Default checkbox values</title>
<body>
<?php
$food = $_get["Food"];//www.3ppt.com
if (!empty ($food)) {
echo "The foods selected are: <strong>";
foreach ($food as $foodstuff) {
echo ' <br/> '. htmlentities ($foodstuff);
}
echo "</STRONG>.";
}
else {
Echo ('
<form action= "'. Htmlentities ($_server["php_self"]). "Method=" get ">
<fieldset>
<label>
Italian
<input type= "checkbox" Name= "food[]" value= "Italian"/>
</label>
<label>
Mexican
<input type= "checkbox" Name= "food[]" value= "Mexican"/>
</label>
<label>
Chinese
<input type= "checkbox" Name= "food[]" value= "Chinese" checked= "checked"/>
</label>
</fieldset>
<input type= "Submit" value= "go!"/>
</form> ');
}
?>
</body>