diff --git a/core/includes/form.inc b/core/includes/form.inc index 5abf669..ad4a1e4 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -1477,6 +1477,20 @@ function _form_validate(&$elements, &$form_state, $form_id = NULL) { // to re-implement the complex logic to figure out whether the field // value is empty. $elements['#required_but_empty'] = TRUE; + // Show a custom #required_error if provided, otherwise try the title. + if (isset($elements['#required_error'])) { + form_error($elements, $elements['#required_error']); + } + // A #title is not mandatory for form elements, but without it we cannot + // set a form error message. So when a visible title is undesirable, form + // constructors are encouraged to set #title anyway, and then set + // #title_display to 'invisible'. This improves accessibility. + elseif (isset($elements['#title'])) { + form_error($elements, t('!name field is required.', array('!name' => $elements['#title']))); + } + else { + form_error($elements); + } } } @@ -1492,26 +1506,6 @@ function _form_validate(&$elements, &$form_state, $form_id = NULL) { } } - // Ensure that a #required form error is thrown, regardless of whether - // #element_validate handlers changed any properties. If $is_empty_value - // is defined, then above #required validation code ran, so the other - // variables are also known to be defined and we can test them again. - if (isset($is_empty_value) && ($is_empty_multiple || $is_empty_string || $is_empty_value)) { - if (isset($elements['#required_error'])) { - form_error($elements, $elements['#required_error']); - } - // A #title is not mandatory for form elements, but without it we cannot - // set a form error message. So when a visible title is undesirable, form - // constructors are encouraged to set #title anyway, and then set - // #title_display to 'invisible'. This improves accessibility. - elseif (isset($elements['#title'])) { - form_error($elements, t('!name field is required.', array('!name' => $elements['#title']))); - } - else { - form_error($elements); - } - } - $elements['#validated'] = TRUE; }