You are here

function form_type_numericfield_value in Format Number API 6

Same name and namespace in other branches
  1. 7 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.

$edit: The incoming POST data 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.

File

./format_number.module, line 481
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, $edit = FALSE) {
  if ($edit !== FALSE) {

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

    // 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;
  }
}