In my Drupal 8 custom module,
I have a form accessible with link '/myform', which once submitted redirected to '/user/1' page.

But the issue is this message '"Current time is ". time()' is shown on both('/myform' and '/user/1') the pages.

class DecisionConfigForm extends FormBase {
  public function buildForm(array $form, FormStateInterface $form_state) {
    drupal_set_message("Current time is ". time()  , 'warning'); // Even I tried with $repeat= FALSE
  }
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->setRedirect($route_name, $route_params); //say, /user/1 page
  }
}

Comments

abhaysaraf created an issue. See original summary.

Version: 8.1.9 » 8.1.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.1.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jeroent’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)
Issue tags: +Bug Smash Initiative

This is by design. BuildForm is called to build the form structure. If we don’t call the build form method, it won’t be possible to build the form array (first parameter the submitForm method).

Feel free to reopen if you still think this is a bug.