O'Reilly logo

Drupal 8 Blueprints by Alex Burrows

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

$form state object

As $form_state is now an object; we no longer need to use arrays to get the values we need.

To get an individual value from the form we will use $form_state->getValue('field_name'); this looks a lot nicer than what we previously had to do in Drupal 7.

So, let's create our submitForm() method and take the values we need from our form submission.

/**  * {@inheritdoc}  */ public function submitForm(array &$form, FormStateInterface  $form_state) {      // Get submitted form values.      $name = $form_state->getValue('name');      $amount = $form_state->getValue('amount');      // Display a thank you message.      drupal_set_message(t('Thank you for the donation of %amount. ',       array('%amount' => $amount)));}

In the preceding code, we are simply going ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required