Forum Moderators: coopster
TIA
But Im not sure thats any better than the solution you mentioned already.
$checkboxarray = 'stone', 'sick_dog', 'ballpoint_pen', 'weasel';
foreach($checkboxarray as $v){
echo "\n".str_replace('_', ' ', $v).' : <input type="checkbox" name="'.$v.'" value="1"';
if(!empty$_GET[$v]) echo ' checked="checked"';
echo ' />';
}
There are many ways...
The first and easiest is simply
print_r($_POST);
Voila! A list of all post vars. Now if you want to actualy be able to do something with those values other than printing them out as a mish mash array listing, you have to do something more. I would approach it like this.
You don't know what the names of the checkboxes are going to be, but you could save yourself a lot of headache (I think) by using an array for your checkbox names. If the name is important you will have to use it as the array index. So your input elements are like this.
<input type="checkbox" name="list[name_from_db]">
Now when you get the post data, you at least know where to look for your list of checkboxes.
foreach($_POST['list'] as $name=>$val)
{
echo "The value of box $name is $val<br>";
}
If I understand what you need, that roughly should do it with some debuigging for typos!
It still doesn't answer your first question about knowing from the submit page which checkboxes need to be checked. In that case, as you pull the data from the DB, you simply check to see whether or not it's true and you flag it as in
$selected = (!empty($val))? ' selected="selected"' : '';
$input_field = '<input type="checkbox" name="arbitrary_value_12ssd3"' . $selected . '">';
Tom