form_get_error

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 – 7 form_get_error($element)

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

Code

includes/form.inc, line 1598

<?php
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];
    }
  }
}
?>