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

up vote 6 down vote accepted

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()));
  • exellent , Thanks for answer. – Yusef Mohamadi Sep 18 '12 at 10:19

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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