You are here

public function MultistepForm::fapiExamplePageTwo in Examples for Developers 8

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

Builds the second step form (page 2).

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The render array defining the elements of the form.

1 call to MultistepForm::fapiExamplePageTwo()
MultistepForm::buildForm in form_api_example/src/Form/MultistepForm.php
Form constructor.

File

form_api_example/src/Form/MultistepForm.php, line 149

Class

MultistepForm
Provides a form with two steps.

Namespace

Drupal\form_api_example\Form

Code

public function fapiExamplePageTwo(array &$form, FormStateInterface $form_state) {
  $form['description'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('A basic multistep form (page 2)'),
  ];
  $form['color'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Favorite color'),
    '#required' => TRUE,
    '#default_value' => $form_state
      ->getValue('color', ''),
  ];
  $form['back'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Back'),
    // Custom submission handler for 'Back' button.
    '#submit' => [
      '::fapiExamplePageTwoBack',
    ],
    // We won't bother validating the required 'color' field, since they
    // have to come back to this page to submit anyway.
    '#limit_validation_errors' => [],
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => $this
      ->t('Submit'),
  ];
  return $form;
}