Drupal: How to Render Results of Form on Same Page as Form

前端 未结 5 1752
走了就别回头了
走了就别回头了 2020-12-10 07:31

How would I print the results of a form submission on the same page as the form itself?

Relevant hook_menu:

    $items[\'admin/content/ncbi_subsites/         


        
5条回答
  •  隐瞒了意图╮
    2020-12-10 07:39

    For Drupal 8, if you have a form implementing FormBase I found I needed to set the form to be rebuilt to allow using the form state during render of the form after a successful form submission:

      public function submitForm(array &$form, FormStateInterface $form_state) {
        $form_state->setRebuild(TRUE);
      }
    

    By default, the form will submit and process the form, then redirect, then build the form again and at that point you don't have the form state (unless you've passed the form state as part of a query parameter in the redirect).

提交回复
热议问题