function TestForm::validateForm

Same name in this branch
  1. 10 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\TestForm::validateForm()
Same name in other branches
  1. 9 core/modules/block/tests/modules/block_test/src/Form/TestForm.php \Drupal\block_test\Form\TestForm::validateForm()
  2. 9 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\TestForm::validateForm()
  3. 8.9.x core/modules/block/tests/modules/block_test/src/Form/TestForm.php \Drupal\block_test\Form\TestForm::validateForm()
  4. 8.9.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\TestForm::validateForm()
  5. 11.x core/modules/block/tests/modules/block_test/src/Form/TestForm.php \Drupal\block_test\Form\TestForm::validateForm()
  6. 11.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\TestForm::validateForm()

Overrides FormBase::validateForm

File

core/modules/block/tests/modules/block_test/src/Form/TestForm.php, line 42

Class

TestForm
Form that performs base block form test.

Namespace

Drupal\block_test\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
    if (!str_contains($form_state->getValue('email'), '.com')) {
        $form_state->setErrorByName('email', $this->t('This is not a .com email address.'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.