function range_float_validate in Range 6
FAPI validation of an individual float element.
1 string reference to 'range_float_validate'
- range_process in ./
range.module - Process an individual element.
File
- ./
range.module, line 536 - Defines numeric fields within a range of possible values and displays them colored accordingly..
Code
function range_float_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)) {
$start = $value;
$value = preg_replace('@[^-0-9\\.]@', '', $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 decimals are allowed in %field. %start was changed to %value.', array(
'%field' => t($field['widget']['label']),
'%start' => $start,
'%value' => $value,
)));
}
form_set_value($element[$field_key], $value, $form_state);
}
}