function form_type_range_value

Determines the value for a range element.

Make sure range elements always have a value. The 'required' attribute is not allowed for range elements.

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

Related topics

File

drupal/core/includes/form.inc, line 4395
Functions for form and batch generation and processing.

Code

function form_type_range_value($element, $input = FALSE) {
  if ($input === '') {
    $offset = ($element['#max'] - $element['#min']) / 2;

    // Round to the step.
    if (strtolower($element['#step']) != 'any') {
      $steps = round($offset / $element['#step']);
      $offset = $element['#step'] * $steps;
    }
    return $element['#min'] + $offset;
  }
}