Same name and namespace in other branches
- 6.x includes/form.inc \form_type_checkboxes_value()
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 $form_state['values'] for this element, or nothing to use the default.
Related topics
1 string reference to 'form_type_checkboxes_value'
- _form_builder_handle_input_element in includes/
form.inc - Adds the #name and #value properties of an input element before rendering.
File
- includes/
form.inc, line 2403 - 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();
}
}