FormTestValidateRequiredNoTitleForm.php 957 Bytes
Newer Older
1 2 3 4 5
<?php

namespace Drupal\form_test\Form;

use Drupal\Core\Form\FormBase;
6
use Drupal\Core\Form\FormStateInterface;
7 8 9

/**
 * Form constructor to test the #required property without #title.
10 11
 *
 * @internal
12 13 14 15 16 17 18 19 20 21 22 23 24
 */
class FormTestValidateRequiredNoTitleForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'form_test_validate_required_form_no_title';
  }

  /**
   * {@inheritdoc}
   */
25
  public function buildForm(array $form, FormStateInterface $form_state) {
26
    $form['textfield'] = [
27 28
      '#type' => 'textfield',
      '#required' => TRUE,
29 30 31
    ];
    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = ['#type' => 'submit', '#value' => 'Submit'];
32 33 34 35 36 37
    return $form;
  }

  /**
   * {@inheritdoc}
   */
38
  public function submitForm(array &$form, FormStateInterface $form_state) {
39 40 41 42
    drupal_set_message('The form_test_validate_required_form_no_title form was submitted successfully.');
  }

}