The problem:
I'm building a set of checkboxes from an array and I want to be able to make them "sticky" so that when a box (or 2 or 3...) is/are checked and the form is submitted, the page will reload with all of the checkboxes again, and the boxes that were previously checked, will remain checked.
Any help would be greatly appreciated.
I think I'm somewhat close, but just can't seem to get it to work:
$count=count($categories);
for ($i=0; $i<$count; $i++) {
print ($categories[$i] . "<br>");
}
print ("<form method='get' name='form1'>");
$switchCategory = array("a" => "Cat1",
"b" => "Cat2",
"c" => "Cat3",
"d" => "Cat4",
"e" => "Cat5",
"f" => "Cat6",
"g" => "Cat7",
"h" => "Cat8");
reset ($switchCategory);
while (list ($key, $value) = each ($switchCategory)) {
if ($key == $categories[$i]) { print ("<input type='checkbox' name='categories[]' value='" . $key . "' checked>" . $value . "<br>"); }
else { print ("<input type='checkbox' name='categories[]' value='" . $key . "'>" . $value . "<br>"); }
}
print ("<input type='submit' value='submit'>");
print ("</form>");
thanks
-B