Commit 463ffe24 authored by Dries's avatar Dries

- Patch #35724 by asimmonds: fixed handling of empty form fields.

parent 17205b6e
...@@ -140,8 +140,10 @@ function _form_validate($elements) { ...@@ -140,8 +140,10 @@ function _form_validate($elements) {
/* Validate the current input */ /* Validate the current input */
if (!$elements['#validated'] && $elements['#input']) { if (!$elements['#validated'] && $elements['#input']) {
if ($elements['#required'] && !isset($elements['#value'])) { // An empty checkbox returns 0, an empty textfield returns '' so we use empty().
form_error($elements, t('%name field is required', array('%name' => $elements['#title']))); // Unfortunately, empty('0') returns TRUE so we need a special check for the '0' string.
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') {
form_error($elements, t('%name field is required', array('%name' => $elements['#title'])));
} }
if ($elements['#valid']) { if ($elements['#valid']) {
if (is_array($elements['#valid'])) { if (is_array($elements['#valid'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment