I have a content type with an integer field with a text field widget. I set minimum value 10000 and maximum value 99999 (like a ZIP code).
When I create new content and enter the value "12-" in that field, there's no validation error. I expected it to cast the value to integer and finding that 12 < 10000, but it didn't.
The problem is in the function number_field() in number.module:
if (is_numeric($field['min']) && $item['value'] < $field['min']) {
form_set_error( ... );
}
if (is_numeric($field['max']) && $item['value'] > $field['max']) {
form_set_error( ... );
}
$item['value'] and $field['min'] are strings, and PHP actually returns FALSE for ("12-" < "10000"), so comparing strings is wrong. Instead both values should be casted to integer or decimal and then compared.
Comments
Comment #1
Roze-1 commentedSubscribing