Widget Checkbox Group – not registering.
-
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!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Widget Checkbox Group – not registering.’ is closed to new replies.