form_type_select_value

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

Helper function to determine the value for a select 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 2340

<?php
function form_type_select_value($element, $input = FALSE) {
  if ($input !== FALSE) {
    if (isset($element['#multiple']) && $element['#multiple']) {
      // If an enabled multi-select submits NULL, it means all items are
      // unselected. A disabled multi-select always submits NULL, and the
      // default value should be used.
      if (empty($element['#disabled'])) {
        return (is_array($input)) ? drupal_map_assoc($input) : array();
      }
      else {
        return (isset($element['#default_value']) && is_array($element['#default_value'])) ? $element['#default_value'] : array();
      }
    }
    // Non-multiple select elements may have an empty option preprended to them
    // (see form_process_select()). When this occurs, usually #empty_value is
    // an empty string, but some forms set #empty_value to integer 0 or some
    // other non-string constant. PHP receives all submitted form input as
    // strings, but if the empty option is selected, set the value to match the
    // empty value exactly.
    elseif (isset($element['#empty_value']) && $input === (string) $element['#empty_value']) {
      return $element['#empty_value'];
    }
    else {
      return $input;
    }
  }
}
?>