function formatted_number_widget_validate in Formatted Number 6
FAPI validation of an individual formatted number field.
1 string reference to 'formatted_number_widget_validate'
- formatted_number_widget_process in ./
formatted_number.module - Process an individual formatted_number element.
File
- ./
formatted_number.module, line 533 - Defines CCK numeric types where thousands separator and decimal point are inherited from the Format Number API module.
Code
function formatted_number_widget_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 = trim($element['#value'][$field_key]);
if ($element[$field_key]['#required'] || $value != '') {
$value = parse_formatted_number($value, $element[$field_key]['#required']);
if (!is_numeric($value)) {
$error_element = implode('][', $element['#parents']) . '][' . $field_key;
form_set_error($error_element, t('The specified number !num is invalid.', array(
'!num' => $element['#value'][$field_key],
)));
return;
}
$errors = formatted_number_validate_field_value($field, $value);
if (!empty($errors)) {
$error_element = implode('][', $element['#parents']) . '][' . $field_key;
foreach ($errors as $message) {
form_set_error($error_element, $message);
}
return;
}
}
// Update the form field with parsed number, so it gets a valid PHP number
// that can be used to store in the database.
if ($element['#value'][$field_key] != $value) {
form_set_value($element[$field_key], $value, $form_state);
}
}