I have checkboxes list in system settings form:

$form['mymodule_menu_perm_menus'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Menus'),
    '#options' => menu_get_menus(TRUE),
    '#default_value' => variable_get('mymodule_menu_perm_menus', array()),        

return system_settings_form($form);

I submit this form with two checkboxes selected.

But on other page variable_get('mymodule_menu_perm_menus') return all values :/

Clearing cache doesn't help


Because Drupal doesn't actually filter out empty checkboxes values, it sets them to zero. I think this is so you get an accurate representation of what options were available when the form was submitted, and what was actually chosen by the user.

It's easy to get the filtered array though, using array_filter():

$values = array_filter(variable_get('mymodule_menu_perm_menus', array()));
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.