TextForm.php in Examples for Developers 3.x
File
modules/theming_example/src/Form/TextForm.php
View source
<?php
namespace Drupal\theming_example\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class TextForm extends FormBase {
public function getFormId() {
return 'theming_example_form_text';
}
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;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addMessage($this
->t('You chose %input', [
'%input' => $form_state
->getValue('text'),
]));
}
}
Classes
Name |
Description |
TextForm |
A simple form that displays a textfield and submit button. |