1 form.inc 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.

Return value

string|NULL: The error message against the given element. NULL if no error was flagged.

Related topics


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


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

  return NULL;