Zend_Form MultiCheckbox not checking boxes
- by azz0r
$groups = Model_UserGroup::load_links($object->id);
foreach ($groups as $item) {
$object->group[$item->group_id] = $item->enabled;
}
$array_object = (array) $object;//turn the object to an array so zend_form can use it
$form->populate($array_object);
enabled = 1 or 0
In the form class:
$group = new Zend_Form_Element_MultiCheckbox('group');
$groups = Model_Group::load_all();
$new_item = array();
foreach ($groups as $item) {
$group->addMultiOption($item->id, $item->name);
}
However the top group is the only one ever checked. Anyone spot anything glaringly wrong? I know its difficult to get a grasp of my layout/setup for this.
Here is the array_object:
Array ( [table_name] => User [id] => 112 [updated] => 1269428783 [created] => 1153237813 [group] => Array ( [1] => 1 [3] => 1 ) )
Here is the html zend_form is creating:
<dd id="group-element">
<label for="group-1"><input name="group[]" id="group-1" value="1" checked="checked" type="checkbox">Administrator Access</label><br>
<label for="group-2"><input name="group[]" id="group-2" value="2" type="checkbox">Content Admin</label><br>
<label for="group-3"><input name="group[]" id="group-3" value="3" type="checkbox">Administrator</label><br>
<label for="group-4"><input name="group[]" id="group-4" value="4" type="checkbox">Studio</label>
</dd>
edit: just done a small test and made the $groups (in the first set of code tags) empty and it still ticks the first box. hm
Fixed this by doing:
//
$selected_groups = Model_UserGroup::load_links($object->id);
$group_ticks = array();
foreach ($selected_groups as $item) {
if ($item->enabled == 1) {
$group_ticks[] = $item->group_id;//$form->group->setValue($item->group_id);
}
}
$form->group->setValue($group_ticks);
//