class TextForm

A simple form that displays a textfield and submit button.

This form will be rendered by the default theme function because we do not provide one.

Hierarchy

  • class \Drupal\theming_example\Form\TextForm extends \Drupal\Core\Form\FormBase

Expanded class hierarchy of TextForm

1 string reference to 'TextForm'
theming_example.routing.yml in modules/theming_example/theming_example.routing.yml
modules/theming_example/theming_example.routing.yml

File

modules/theming_example/src/Form/TextForm.php, line 14

Namespace

Drupal\theming_example\Form
View source
class TextForm extends FormBase {
  
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'theming_example_form_text';
  }
  
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['text'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Please input something!'),
      '#required' => TRUE,
    ];
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Go'),
    ];
    return $form;
  }
  
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->messenger()
      ->addMessage($this->t('You chose %input', [
      '%input' => $form_state->getValue('text'),
    ]));
  }

}

Members

Title Sort descending Modifiers Object type Summary
TextForm::buildForm public function
TextForm::getFormId public function
TextForm::submitForm public function