You are here

function form_type_numericfield_value in Format Number API 7

Same name and namespace in other branches
  1. 6 format_number.module \form_type_numericfield_value()

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

See also

form_type_textfield_value()

File

./format_number.module, line 490
This module provides a method to configure number formats (site default and user defined) with configurable decimal point and thousand separators. It also exposes several functions that can be used by other contributed or custom modules to display…

Code

function form_type_numericfield_value($element, $input = FALSE) {
  if ($input !== FALSE && $input !== NULL) {

    // Equate $input to the form value to ensure it's marked for validation.
    $value = trim(str_replace(array(
      "\r",
      "\n",
    ), '', $input));

    // If input is not empty, we want a valid PHP number now.
    // If input cannot be parsed as a valid PHP number, our element validation
    // callback will take care of it.
    if ($value != '' && ($parsed = parse_formatted_number($value)) !== FALSE) {
      $value = $parsed;
    }
    return $value;
  }
}