function range_decimal_validate in Range 6
FAPI validation of an individual decimal element.
1 string reference to 'range_decimal_validate'
- range_process in ./
range.module - Process an individual element.
File
- ./
range.module, line 582 - Defines numeric fields within a range of possible values and displays them colored accordingly..
Code
function range_decimal_validate($element, &$form_state) {
$field_name = $element['#field_name'];
$type_name = $element['#type_name'];
$field = content_fields($field_name, $type_name);
$field_key = $element['#columns'][0];
$value = $element['#value'][$field_key];
if ($element[$field_key]['#required'] || !empty($value)) {
$decimal = $element['#decimal'] ? $element['#decimal'] : '.';
$start = $value;
$value = preg_replace('@[^-0-9\\' . $decimal . ']@', '', $value);
if ($start != $value) {
// No reason to make this an error, just need to inform user what has changed.
drupal_set_message(t('Only numbers and the decimal character (%decimal) are allowed in %field. %start was changed to %value.', array(
'%decimal' => $element['#decimal'],
'%field' => t($field['widget']['label']),
'%start' => $start,
'%value' => $value,
)));
}
$value = str_replace($element['#decimal'], '.', $value);
$value = round($value, $element['#scale']);
form_set_value($element[$field_key], $value, $form_state);
}
}