You are here

function expand_checkboxes in Drupal 5

Same name and namespace in other branches
  1. 4 includes/form.inc \expand_checkboxes()
  2. 6 includes/form.inc \expand_checkboxes()

Related topics

File

includes/form.inc, line 1349

Code

function expand_checkboxes($element) {
  $value = is_array($element['#value']) ? $element['#value'] : array();
  $element['#tree'] = TRUE;
  if (count($element['#options']) > 0) {
    if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
      $element['#default_value'] = array();
    }
    foreach ($element['#options'] as $key => $choice) {
      if (!isset($element[$key])) {
        $element[$key] = array(
          '#type' => 'checkbox',
          '#processed' => TRUE,
          '#title' => $choice,
          '#return_value' => $key,
          '#default_value' => isset($value[$key]),
          '#attributes' => $element['#attributes'],
        );
      }
    }
  }
  return $element;
}