function form_type_checkboxes_value
form_type_checkboxes_value($element, $input = FALSE)
Determines 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
File
- includes/form.inc, line 2386
- Functions for form and batch generation and processing.
Code
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(); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!form.inc/function/form_type_checkboxes_value/7.x