Quote:
Originally Posted by Vigilante23
Ok I see what you did there. But how do I capture a string with a checkbox?
|
The selected boxes are added to an array, and you retrieve the values with a foreach loop. You need square braces around the name value in the form.
PHP Code:
<?php
if (isset($_POST['submit'])) {
$color = $_POST['color'];
foreach ($color as $value){
echo "You checked: $value<br>";
}
}
$colors = array('blue','green','black','gold','silver','white','purple','red');
echo "<form method=\"post\" action=\"test.php\">";
foreach ($colors as $color){
echo "<input type=\"checkbox\" name=\"color[]\" value=\"$color\">$color<br>";
}
echo "<input type=\"submit\" value=\"Pick a Color\" name=\"submit\">";
?>
Ouput
Code:
You checked: black
You checked: white
You checked: red