Hi,
I'm having difficulties getting my checkboxes to save in a widget I'm developing. I'm pulling out the categories and displaying them as checkboxes, but I want them as a group as opposed to individual.
Saving checkbox group value using below -
$instance['gallerycats[]'] = isset($new_instance['gallerycats[]']);
Displaying the checkboxes as follows -
$categories= get_categories();
foreach ($categories as $cat) {
$option='<input type="checkbox" id="'. $this->get_field_id( 'gallerycats[]' ) .'" name="'. $this->get_field_name( 'gallerycats[]' ) .'"';
if (is_array($instance['gallerycats[]'])) {
foreach ($instance['gallerycats[]'] as $cats) {
if($cats==$cat->term_id) {
$option=$option.' checked="checked"';
}
}
}
$option .= ' value="'.$cat->term_id.'" />';
$option .= $cat->cat_name;
$option .= ' ('.$cat->category_count.')';
$option .= '<br />';
echo $option;
}
Thanks in advance!