3 namespace Drupal\block_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
8 class TestForm extends FormBase {
13 public function getFormId() {
14 return 'block_test_form_test';
20 public function buildForm(array $form, FormStateInterface $form_state) {
23 '#title' => $this->t('Your .com email address.')
28 '#value' => $this->t('Submit'),
37 public function validateForm(array &$form, FormStateInterface $form_state) {
38 if (strpos($form_state->getValue('email'), '.com') === FALSE) {
39 $form_state->setErrorByName('email', $this->t('This is not a .com email address.'));
46 public function submitForm(array &$form, FormStateInterface $form_state) {
47 drupal_set_message($this->t('Your email address is @email', ['@email' => $form['email']['#value']]));