I am having trouble returning only checked items from a list of items. Instead of returning only the checked items, I get the full list of checkboxes: selected or not.
I have a form that returns a number of list of items with checkboxes. It seems to be working correctly, saving the users preference and correctly assigning checked="checked" to items they pick.
It is generated as follows:
foreach ($this->item as $code => $value) {
$checked = $this->settings['item'][$code] ? "checked='checked'" : '';
$output .= "<label style=\"margin-left: 20px;\"><input type='checkbox' {$checked} name='options[item][{$code}]'/>{$this->item[$code]}</label><br />\n\r";
}
I want to return ONLY the values of the selected checkboxes.
This is what I have been trying:
foreach ($_POST['items'] as $value) {
echo "the value are: ".$value;
}
This returns all of the items instead of only the selected ones.
I have also tried:
$item = $this->item;
foreach($item as $code) {
print $code;
}
This also returns all checked and non checked items.
Can anybody point me to where the problem is?
Any help is greatly appreciated!
I am not sure what you are asking, but I assume that you want the ones which are previously checked. So, try this: