function MultistepForm::fapiExampleMultistepFormNextValidate
Same name in other branches
- 8.x-1.x form_api_example/src/Form/MultistepForm.php \Drupal\form_api_example\Form\MultistepForm::fapiExampleMultistepFormNextValidate()
- 4.0.x modules/form_api_example/src/Form/MultistepForm.php \Drupal\form_api_example\Form\MultistepForm::fapiExampleMultistepFormNextValidate()
Provides custom validation handler for page 1.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
-
modules/
form_api_example/ src/ Form/ MultistepForm.php, line 106
Class
- MultistepForm
- Provides a form with two steps.
Namespace
Drupal\form_api_example\FormCode
public function fapiExampleMultistepFormNextValidate(array &$form, FormStateInterface $form_state) {
$birth_year = $form_state->getValue('birth_year');
if ($birth_year != '' && ($birth_year < 1900 || $birth_year > 2000)) {
// Set an error for the form element with a key of "birth_year".
$form_state->setErrorByName('birth_year', $this->t('Enter a year between 1900 and 2000.'));
}
}