You are here

function form_get_error in Drupal 7

Same name and namespace in other branches
  1. 4 includes/form.inc \form_get_error()
  2. 5 includes/form.inc \form_get_error()
  3. 6 includes/form.inc \form_get_error()

Returns the error message filed against the given form element.

Form errors higher up in the form structure override deeper errors as well as errors on the element itself.

Related topics

1 call to form_get_error()
_form_set_class in includes/form.inc
Sets a form element's class attribute.

File

includes/form.inc, line 1697
Functions for form and batch generation and processing.

Code

function form_get_error($element) {
  $form = form_set_error();
  $parents = array();
  foreach ($element['#parents'] as $parent) {
    $parents[] = $parent;
    $key = implode('][', $parents);
    if (isset($form[$key])) {
      return $form[$key];
    }
  }
}