You are here

public function SimpleForm::submitForm in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/form_api_example/src/Form/SimpleForm.php \Drupal\form_api_example\Form\SimpleForm::submitForm()

Implements a form submit handler.

The submitForm method is the default method called for any submit elements.

Parameters

array $form: The render array of the currently built form.

\Drupal\Core\Form\FormStateInterface $form_state: Object describing the current state of the form.

Overrides FormInterface::submitForm

File

form_api_example/src/Form/SimpleForm.php, line 105

Class

SimpleForm
Implements the SimpleForm form controller.

Namespace

Drupal\form_api_example\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  /*
   * This would normally be replaced by code that actually does something
   * with the title.
   */
  $title = $form_state
    ->getValue('title');
  $this
    ->messenger()
    ->addMessage($this
    ->t('You specified a title of %title.', [
    '%title' => $title,
  ]));
}