Skip to main content

How to keep your custom form submitted values in drupal 8 (form_state setRebuild)?

In custom module path (web/modules/custom/my_custom_module/src/Form/MyCustomModuleForm.php) add this line in your submitForm method

<?php
/**
 * @file
 */
namespace Drupal\myCustomModule\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;


class myCustomModuleForm extends FormBase {
. . . .
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    //As in drupal 7 now in drupal 8 you need to set the form state rebuild value to TRUE
    $form_state->setRebuild(true);
  }

 

form