I feel like I'm crazy because I never find the answers to the most basic questions. I have a module settings page where I want to list CCK fields with certain characteristics and make them selectable through checkboxes. Here is the code:

function mymodule_settings_form() {

  $fields = content_fields();

  foreach ($fields as $field){

    // Show only fields with checkboxes, radio buttons or select list
    if ($field['type'] == 'text' && $field['widget']['module'] == 'optionwidgets') $options[$field['field_name']] = $field['widget']['label'];

  }

  // Define a textarea
  $form['metis_cck_fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select a field'),
    '#description' => t('Please select a field'),
    '#options'  => $options,
  );

  // This is supposed to help...
  $form['array_filter'] = array('#type' => 'hidden');

  return system_settings_form($form);

}

But the settings are not saved. Any hints why?

Comments

sepla’s picture

Removed.

prakashp’s picture

You just need to add the #default_value

  $form['metis_cck_fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select a field'),
    '#description' => t('Please select a field'),
    '#default_value' => variable_get('metis_cck_fields', array()),
    '#options'  => $options,
  );
yan’s picture

That was it! Thanks a lot.