form_type_checkboxes_value

  1. drupal
    1. 6
    2. 8
    3. 7
Versions
6 form_type_checkboxes_value($form, $edit = FALSE)
7 – 8 form_type_checkboxes_value($element, $input = FALSE)

Helper function to determine the value for a checkboxes form element.

Parameters

$element The form element whose value is being populated.

$input The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.

Return value

The data that will appear in the $element_state['values'] collection for this element. Return nothing to use the default.

Related topics

Code

includes/form.inc, line 2245

<?php
function form_type_checkboxes_value($element, $input = FALSE) {
  if ($input === FALSE) {
    $value = array();
    $element += array('#default_value' => array());
    foreach ($element['#default_value'] as $key) {
      $value[$key] = $key;
    }
    return $value;
  }
  elseif (is_array($input)) {
    // Programmatic form submissions use NULL to indicate that a checkbox
    // should be unchecked; see drupal_form_submit(). We therefore remove all
    // NULL elements from the array before constructing the return value, to
    // simulate the behavior of web browsers (which do not send unchecked
    // checkboxes to the server at all). This will not affect non-programmatic
    // form submissions, since all values in $_POST are strings.
    foreach ($input as $key => $value) {
      if (!isset($value)) {
        unset($input[$key]);
      }
    }
    return drupal_map_assoc($input);
  }
  else {
    return array();
  }
}
?>