You are here

public function FormValidatorInterface::validateForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Form/FormValidatorInterface.php \Drupal\Core\Form\FormValidatorInterface::validateForm()
  2. 10 core/lib/Drupal/Core/Form/FormValidatorInterface.php \Drupal\Core\Form\FormValidatorInterface::validateForm()

Validates user-submitted form data in the $form_state.

Parameters

$form_id: A unique string identifying the form for validation, submission, theming, and hook_form_alter functions.

$form: An associative array containing the structure of the form, which is passed by reference. Form validation handlers are able to alter the form structure (like #process and #after_build callbacks during form building) in case of a validation error. If a validation handler alters the form structure, it is responsible for validating the values of changed form elements in $form_state->getValues() to prevent form submit handlers from receiving unvalidated values.

$form_state: The current state of the form. The current user-submitted data is stored in $form_state->getValues(), though form validation functions are passed an explicit copy of the values for the sake of simplicity. Validation handlers can also use $form_state to pass information on to submit handlers. For example: $form_state->set('data_for_submission', $data); This technique is useful when validation requires file parsing, web service requests, or other expensive requests that should not be repeated in the submission step.

2 methods override FormValidatorInterface::validateForm()
FormBuilder::validateForm in core/lib/Drupal/Core/Form/FormBuilder.php
Validates user-submitted form data in the $form_state.
FormValidator::validateForm in core/lib/Drupal/Core/Form/FormValidator.php
Validates user-submitted form data in the $form_state.

File

core/lib/Drupal/Core/Form/FormValidatorInterface.php, line 50

Class

FormValidatorInterface
Provides an interface for validating form submissions.

Namespace

Drupal\Core\Form

Code

public function validateForm($form_id, &$form, FormStateInterface &$form_state);