function form_type_select_value

Determines 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 $form_state['values'] for this element, or nothing to use the default.

Related topics

File

includes/form.inc, line 2550

Code

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();
            }
        }
        elseif (isset($element['#empty_value']) && $input === (string) $element['#empty_value']) {
            return $element['#empty_value'];
        }
        else {
            return $input;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.