I have a function that takes in 2 params ($group, $array)
$group = the ‘name’ of the input attribute
$array = the array of checkbox values
function checkboxes($group, $array) {
$string = NULL;
$group = (string)$group."[]";
foreach($array as $key => $value) {
$string .= "<br /><input type='checkbox' id=".$value." name='".$group."' value='".$value."' /><label for=".$value.">$value</label>";
}
return $string;
}
What I’m trying to do is convert that into proper HTML, so that I can process the value in a script.
here is the input:
checkboxes("class", array("Warrior","Mage","Priest","Rogue"));
$boxes = $_POST['class'];
for ($i=0; $i<count($boxes); $i++) {
echo $boxes[$i];
}
Output: “R” (when more than one are checked as well)
Any help would be great, sorry if I forgot anything.
This is homework, so don’t give me answers that break the stackoverflow terms/my schools honor code please!
Try this. It seems to print all checked boxes.