public function FormErrorHandler::handleFormErrors

public FormErrorHandler::handleFormErrors(array &$form, FormStateInterface $form_state)

Handles form errors after form validation.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

$this

Overrides FormErrorHandlerInterface::handleFormErrors

File

core/lib/Drupal/Core/Form/FormErrorHandler.php, line 15

Class

FormErrorHandler
Handles form errors.

Namespace

Drupal\Core\Form

Code

public function handleFormErrors(array &$form, FormStateInterface $form_state) {
  // After validation check if there are errors.
  if ($errors = $form_state->getErrors()) {
    // Display error messages for each element.
    $this->displayErrorMessages($form, $form_state);

    // Loop through and assign each element its errors.
    $this->setElementErrorsFromFormState($form, $form_state);
  }

  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormErrorHandler.php/function/FormErrorHandler::handleFormErrors/8.1.x