W3cubDocs

/Drupal 7

function form_type_radios_value

form_type_radios_value(&$element, $input = FALSE)

Form value callback: Determines the value for a #type radios form element.

Parameters

$element: The form element whose value is being populated.

$input: (optional) The incoming input to populate the form element. If FALSE, the element's default value is returned. Defaults to FALSE.

Return value

The data that will appear in the $element_state['values'] collection for this element.

Related topics

File

includes/form.inc, line 2463
Functions for form and batch generation and processing.

Code

function form_type_radios_value(&$element, $input = FALSE) {
  if ($input !== FALSE) {
    // When there's user input (including NULL), return it as the value.
    // However, if NULL is submitted, _form_builder_handle_input_element() will
    // apply the default value, and we want that validated against #options
    // unless it's empty. (An empty #default_value, such as NULL or FALSE, can
    // be used to indicate that no radio button is selected by default.)
    if (!isset($input) && !empty($element['#default_value'])) {
      $element['#needs_validation'] = TRUE;
    }
    return $input;
  }
  else {
    // For default value handling, simply return #default_value. Additionally,
    // for a NULL default value, set #has_garbage_value to prevent
    // _form_builder_handle_input_element() converting the NULL to an empty
    // string, so that code can distinguish between nothing selected and the
    // selection of a radio button whose value is an empty string.
    $value = isset($element['#default_value']) ? $element['#default_value'] : NULL;
    if (!isset($value)) {
      $element['#has_garbage_value'] = TRUE;
    }
    return $value;
  }
}

© 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_radios_value/7.x