How to to redirect a form to a certain node for anonymous users?Exposing a form to anonymous usersHow to display the output of a form?URL specific form for anonymous userHow to validate all elements in Custom WidgetHow do I check login?How can I set a default node owner for anonymous nodes on the node edit form?How to do a hard redirect when in ajaxified form?How can i set the value of first field to the second in same formAccess data from previously submitted values in buildForm in FormBase pluginDrupal custom module code working differently for logged in users and anonymous users

Is "history" a male-biased word ("his+story")?

Placing subfig vertically

Peter's Strange Word

How to edit the properties of a page programmatically?

Reverse string, can I make it faster?

Why don't MCU characters ever seem to have language issues?

Am I not good enough for you?

Examples of a statistic that is not independent of sample's distribution?

PTIJ: Why can't I eat anything?

Why would one plane in this picture not have gear down yet?

How can The Temple of Elementary Evil reliably protect itself against kinetic bombardment?

Accountant/ lawyer will not return my call

Force user to remove USB token

Can someone explain what is being said here in color publishing in the American Mathematical Monthly?

They call me Inspector Morse

Should I take out a loan for a friend to invest on my behalf?

Can a bounded number sequence be strictly ascending?

Is Gradient Descent central to every optimizer?

Is there a window switcher for GNOME that shows the actual window?

What is the likely impact of grounding an entire aircraft series?

The bar has been raised

How strictly should I take "Candidates must be local"?

PTIJ: How can I halachically kill a vampire?

Rejected in 4th interview round citing insufficient years of experience



How to to redirect a form to a certain node for anonymous users?


Exposing a form to anonymous usersHow to display the output of a form?URL specific form for anonymous userHow to validate all elements in Custom WidgetHow do I check login?How can I set a default node owner for anonymous nodes on the node edit form?How to do a hard redirect when in ajaxified form?How can i set the value of first field to the second in same formAccess data from previously submitted values in buildForm in FormBase pluginDrupal custom module code working differently for logged in users and anonymous users













2















In a custom module, I have a form that is triggered by an option in a menu.

I'd want this form to be redirected automatically (without action of the user) to a certain node (/node/2) when the user is not authenticated.

In the public function buildForm(array $form, FormStateInterface $form_state) {, I know how to not display the fields of the form for the anonymous user:



$oCurrentUser = Drupal::currentUser();
if ($oCurrentUser->isAnonymous())
else

some fields...

$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
return $form;



I guess that redirection might be done with $form_state->setRedirect('entity.node.canonical', ['node' => 2]);
but I don't know how to make it work...

Any idea?










share|improve this question


























    2















    In a custom module, I have a form that is triggered by an option in a menu.

    I'd want this form to be redirected automatically (without action of the user) to a certain node (/node/2) when the user is not authenticated.

    In the public function buildForm(array $form, FormStateInterface $form_state) {, I know how to not display the fields of the form for the anonymous user:



    $oCurrentUser = Drupal::currentUser();
    if ($oCurrentUser->isAnonymous())
    else

    some fields...

    $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this->t('Submit'),
    ];
    return $form;



    I guess that redirection might be done with $form_state->setRedirect('entity.node.canonical', ['node' => 2]);
    but I don't know how to make it work...

    Any idea?










    share|improve this question
























      2












      2








      2


      1






      In a custom module, I have a form that is triggered by an option in a menu.

      I'd want this form to be redirected automatically (without action of the user) to a certain node (/node/2) when the user is not authenticated.

      In the public function buildForm(array $form, FormStateInterface $form_state) {, I know how to not display the fields of the form for the anonymous user:



      $oCurrentUser = Drupal::currentUser();
      if ($oCurrentUser->isAnonymous())
      else

      some fields...

      $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
      ];
      return $form;



      I guess that redirection might be done with $form_state->setRedirect('entity.node.canonical', ['node' => 2]);
      but I don't know how to make it work...

      Any idea?










      share|improve this question














      In a custom module, I have a form that is triggered by an option in a menu.

      I'd want this form to be redirected automatically (without action of the user) to a certain node (/node/2) when the user is not authenticated.

      In the public function buildForm(array $form, FormStateInterface $form_state) {, I know how to not display the fields of the form for the anonymous user:



      $oCurrentUser = Drupal::currentUser();
      if ($oCurrentUser->isAnonymous())
      else

      some fields...

      $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
      ];
      return $form;



      I guess that redirection might be done with $form_state->setRedirect('entity.node.canonical', ['node' => 2]);
      but I don't know how to make it work...

      Any idea?







      8 forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 13 hours ago









      gbmapogbmapo

      369315




      369315




















          3 Answers
          3






          active

          oldest

          votes


















          2














          In buildForm() you can return a redirect response the same way as in a controller:



           public function buildForm(array $form, FormStateInterface $form_state) 
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);


          // build $form for authenticated users

          return $form;



          Use $form_state->setRedirect() if you want to redirect in a form submit handler.






          share|improve this answer




















          • 1





            Is there any core module that does that? FormInterface::buildForm() is documented to return an array.

            – kiamlaluno
            12 hours ago











          • @kiamlaluno, FormBuilder::retrieveForm "... the Form API currently allows any form builder functions to return a response."

            – 4k4
            11 hours ago












          • @kiamlaluno, example ModulesListConfirmForm::buildForm

            – 4k4
            11 hours ago


















          2














          The class implementing FormInterface is allowed to return an instance of a class extending the Response class, despite FormInterface::buildForm() not documenting it. See what a comment in the FormBuilder::retrieveForm() code says.




          Exceptions should not be used for code flow control. However, the Form API currently allows any form builder functions to return a response.




          This means that code similar to the following one would actually work.



          public function buildForm(array $form, FormStateInterface $form_state) 
          // Verify the currently logged in user is an anonymous user and redirect.
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);




          Although, since Do not allow form builder functions to return Response objects is open for Drupal 8.8.x, that code could not work anymore, in future.



          A module that works also after the change described in that issue is implemented would:



          • Associate a controller to the route, not a form builder


          • In the controller method associated with the route, redirect the anonymous users to the node page, or render the form for authenticated users



            class RedirectOrFormController extends ControllerBase 
            public function showForm()
            if ($this->currentUser()->isAnonymous())
            return $this->redirect('entity.node.canonical', ['node' => 2]);


            return $this->formBuilder()->getForm('Drupal\locale\Form\TranslateEditForm');




          Replace 'Drupal\locale\Form\TranslateEditForm' with the fully qualified name of the form builder.






          share|improve this answer

























          • This is a good point, but this is the same for FormAjaxException. I think if core succeeds to control the code flow of the Form API without exceptions (which is very unlikely to happen before Drupal 9), it wouldn't affect much of custom code.

            – 4k4
            7 hours ago











          • Actually, the patch for that issue removes the part handling an instance of a class extending the Response class and it forces form builders to return an array from their buildForm() method.

            – kiamlaluno
            6 hours ago











          • This patch is from 2015 when core maintainers were more ambitious to remove exceptions for code flow control. We don't know what they will decide if this issue is picked up again and they might consider a replacement for redirecting in form builders directly.

            – 4k4
            6 hours ago











          • The point is not removing an exception. In fact, the code would still throw an exception, if that patch would be committed to Drupal core.

            – kiamlaluno
            5 hours ago











          • Why should the patch be committed after four years when there is no reason for it anymore since the introduction of EnforcedResponseException? There is of course the point "Exceptions should not be used for code flow control." If this is resolved the patch might be revisited, but probably in a different form and by having a solution to rewrite existing code if necessary.

            – 4k4
            4 hours ago



















          0














          yes, you are right. you can redirect to the node using the code that you have mentioned. There is another way to set the redirection check the below code.



          use the name space :



           
          use SymfonyComponentHttpFoundationRedirectResponse;
          $response = new RedirectResponse(node url);
          $response->send();
          exit(0);


          I don't know what you are trying to achieve hope this code may help you.






          share|improve this answer


















          • 1





            exits should not be needed

            – Kevin
            9 hours ago











          • @Kevin is correct: exit() should not be used.

            – kiamlaluno
            8 hours ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "220"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f277594%2fhow-to-to-redirect-a-form-to-a-certain-node-for-anonymous-users%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          In buildForm() you can return a redirect response the same way as in a controller:



           public function buildForm(array $form, FormStateInterface $form_state) 
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);


          // build $form for authenticated users

          return $form;



          Use $form_state->setRedirect() if you want to redirect in a form submit handler.






          share|improve this answer




















          • 1





            Is there any core module that does that? FormInterface::buildForm() is documented to return an array.

            – kiamlaluno
            12 hours ago











          • @kiamlaluno, FormBuilder::retrieveForm "... the Form API currently allows any form builder functions to return a response."

            – 4k4
            11 hours ago












          • @kiamlaluno, example ModulesListConfirmForm::buildForm

            – 4k4
            11 hours ago















          2














          In buildForm() you can return a redirect response the same way as in a controller:



           public function buildForm(array $form, FormStateInterface $form_state) 
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);


          // build $form for authenticated users

          return $form;



          Use $form_state->setRedirect() if you want to redirect in a form submit handler.






          share|improve this answer




















          • 1





            Is there any core module that does that? FormInterface::buildForm() is documented to return an array.

            – kiamlaluno
            12 hours ago











          • @kiamlaluno, FormBuilder::retrieveForm "... the Form API currently allows any form builder functions to return a response."

            – 4k4
            11 hours ago












          • @kiamlaluno, example ModulesListConfirmForm::buildForm

            – 4k4
            11 hours ago













          2












          2








          2







          In buildForm() you can return a redirect response the same way as in a controller:



           public function buildForm(array $form, FormStateInterface $form_state) 
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);


          // build $form for authenticated users

          return $form;



          Use $form_state->setRedirect() if you want to redirect in a form submit handler.






          share|improve this answer















          In buildForm() you can return a redirect response the same way as in a controller:



           public function buildForm(array $form, FormStateInterface $form_state) 
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);


          // build $form for authenticated users

          return $form;



          Use $form_state->setRedirect() if you want to redirect in a form submit handler.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 12 hours ago

























          answered 12 hours ago









          4k44k4

          52.1k561104




          52.1k561104







          • 1





            Is there any core module that does that? FormInterface::buildForm() is documented to return an array.

            – kiamlaluno
            12 hours ago











          • @kiamlaluno, FormBuilder::retrieveForm "... the Form API currently allows any form builder functions to return a response."

            – 4k4
            11 hours ago












          • @kiamlaluno, example ModulesListConfirmForm::buildForm

            – 4k4
            11 hours ago












          • 1





            Is there any core module that does that? FormInterface::buildForm() is documented to return an array.

            – kiamlaluno
            12 hours ago











          • @kiamlaluno, FormBuilder::retrieveForm "... the Form API currently allows any form builder functions to return a response."

            – 4k4
            11 hours ago












          • @kiamlaluno, example ModulesListConfirmForm::buildForm

            – 4k4
            11 hours ago







          1




          1





          Is there any core module that does that? FormInterface::buildForm() is documented to return an array.

          – kiamlaluno
          12 hours ago





          Is there any core module that does that? FormInterface::buildForm() is documented to return an array.

          – kiamlaluno
          12 hours ago













          @kiamlaluno, FormBuilder::retrieveForm "... the Form API currently allows any form builder functions to return a response."

          – 4k4
          11 hours ago






          @kiamlaluno, FormBuilder::retrieveForm "... the Form API currently allows any form builder functions to return a response."

          – 4k4
          11 hours ago














          @kiamlaluno, example ModulesListConfirmForm::buildForm

          – 4k4
          11 hours ago





          @kiamlaluno, example ModulesListConfirmForm::buildForm

          – 4k4
          11 hours ago













          2














          The class implementing FormInterface is allowed to return an instance of a class extending the Response class, despite FormInterface::buildForm() not documenting it. See what a comment in the FormBuilder::retrieveForm() code says.




          Exceptions should not be used for code flow control. However, the Form API currently allows any form builder functions to return a response.




          This means that code similar to the following one would actually work.



          public function buildForm(array $form, FormStateInterface $form_state) 
          // Verify the currently logged in user is an anonymous user and redirect.
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);




          Although, since Do not allow form builder functions to return Response objects is open for Drupal 8.8.x, that code could not work anymore, in future.



          A module that works also after the change described in that issue is implemented would:



          • Associate a controller to the route, not a form builder


          • In the controller method associated with the route, redirect the anonymous users to the node page, or render the form for authenticated users



            class RedirectOrFormController extends ControllerBase 
            public function showForm()
            if ($this->currentUser()->isAnonymous())
            return $this->redirect('entity.node.canonical', ['node' => 2]);


            return $this->formBuilder()->getForm('Drupal\locale\Form\TranslateEditForm');




          Replace 'Drupal\locale\Form\TranslateEditForm' with the fully qualified name of the form builder.






          share|improve this answer

























          • This is a good point, but this is the same for FormAjaxException. I think if core succeeds to control the code flow of the Form API without exceptions (which is very unlikely to happen before Drupal 9), it wouldn't affect much of custom code.

            – 4k4
            7 hours ago











          • Actually, the patch for that issue removes the part handling an instance of a class extending the Response class and it forces form builders to return an array from their buildForm() method.

            – kiamlaluno
            6 hours ago











          • This patch is from 2015 when core maintainers were more ambitious to remove exceptions for code flow control. We don't know what they will decide if this issue is picked up again and they might consider a replacement for redirecting in form builders directly.

            – 4k4
            6 hours ago











          • The point is not removing an exception. In fact, the code would still throw an exception, if that patch would be committed to Drupal core.

            – kiamlaluno
            5 hours ago











          • Why should the patch be committed after four years when there is no reason for it anymore since the introduction of EnforcedResponseException? There is of course the point "Exceptions should not be used for code flow control." If this is resolved the patch might be revisited, but probably in a different form and by having a solution to rewrite existing code if necessary.

            – 4k4
            4 hours ago
















          2














          The class implementing FormInterface is allowed to return an instance of a class extending the Response class, despite FormInterface::buildForm() not documenting it. See what a comment in the FormBuilder::retrieveForm() code says.




          Exceptions should not be used for code flow control. However, the Form API currently allows any form builder functions to return a response.




          This means that code similar to the following one would actually work.



          public function buildForm(array $form, FormStateInterface $form_state) 
          // Verify the currently logged in user is an anonymous user and redirect.
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);




          Although, since Do not allow form builder functions to return Response objects is open for Drupal 8.8.x, that code could not work anymore, in future.



          A module that works also after the change described in that issue is implemented would:



          • Associate a controller to the route, not a form builder


          • In the controller method associated with the route, redirect the anonymous users to the node page, or render the form for authenticated users



            class RedirectOrFormController extends ControllerBase 
            public function showForm()
            if ($this->currentUser()->isAnonymous())
            return $this->redirect('entity.node.canonical', ['node' => 2]);


            return $this->formBuilder()->getForm('Drupal\locale\Form\TranslateEditForm');




          Replace 'Drupal\locale\Form\TranslateEditForm' with the fully qualified name of the form builder.






          share|improve this answer

























          • This is a good point, but this is the same for FormAjaxException. I think if core succeeds to control the code flow of the Form API without exceptions (which is very unlikely to happen before Drupal 9), it wouldn't affect much of custom code.

            – 4k4
            7 hours ago











          • Actually, the patch for that issue removes the part handling an instance of a class extending the Response class and it forces form builders to return an array from their buildForm() method.

            – kiamlaluno
            6 hours ago











          • This patch is from 2015 when core maintainers were more ambitious to remove exceptions for code flow control. We don't know what they will decide if this issue is picked up again and they might consider a replacement for redirecting in form builders directly.

            – 4k4
            6 hours ago











          • The point is not removing an exception. In fact, the code would still throw an exception, if that patch would be committed to Drupal core.

            – kiamlaluno
            5 hours ago











          • Why should the patch be committed after four years when there is no reason for it anymore since the introduction of EnforcedResponseException? There is of course the point "Exceptions should not be used for code flow control." If this is resolved the patch might be revisited, but probably in a different form and by having a solution to rewrite existing code if necessary.

            – 4k4
            4 hours ago














          2












          2








          2







          The class implementing FormInterface is allowed to return an instance of a class extending the Response class, despite FormInterface::buildForm() not documenting it. See what a comment in the FormBuilder::retrieveForm() code says.




          Exceptions should not be used for code flow control. However, the Form API currently allows any form builder functions to return a response.




          This means that code similar to the following one would actually work.



          public function buildForm(array $form, FormStateInterface $form_state) 
          // Verify the currently logged in user is an anonymous user and redirect.
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);




          Although, since Do not allow form builder functions to return Response objects is open for Drupal 8.8.x, that code could not work anymore, in future.



          A module that works also after the change described in that issue is implemented would:



          • Associate a controller to the route, not a form builder


          • In the controller method associated with the route, redirect the anonymous users to the node page, or render the form for authenticated users



            class RedirectOrFormController extends ControllerBase 
            public function showForm()
            if ($this->currentUser()->isAnonymous())
            return $this->redirect('entity.node.canonical', ['node' => 2]);


            return $this->formBuilder()->getForm('Drupal\locale\Form\TranslateEditForm');




          Replace 'Drupal\locale\Form\TranslateEditForm' with the fully qualified name of the form builder.






          share|improve this answer















          The class implementing FormInterface is allowed to return an instance of a class extending the Response class, despite FormInterface::buildForm() not documenting it. See what a comment in the FormBuilder::retrieveForm() code says.




          Exceptions should not be used for code flow control. However, the Form API currently allows any form builder functions to return a response.




          This means that code similar to the following one would actually work.



          public function buildForm(array $form, FormStateInterface $form_state) 
          // Verify the currently logged in user is an anonymous user and redirect.
          if ($this->currentUser()->isAnonymous())
          return $this->redirect('entity.node.canonical', ['node' => 2]);




          Although, since Do not allow form builder functions to return Response objects is open for Drupal 8.8.x, that code could not work anymore, in future.



          A module that works also after the change described in that issue is implemented would:



          • Associate a controller to the route, not a form builder


          • In the controller method associated with the route, redirect the anonymous users to the node page, or render the form for authenticated users



            class RedirectOrFormController extends ControllerBase 
            public function showForm()
            if ($this->currentUser()->isAnonymous())
            return $this->redirect('entity.node.canonical', ['node' => 2]);


            return $this->formBuilder()->getForm('Drupal\locale\Form\TranslateEditForm');




          Replace 'Drupal\locale\Form\TranslateEditForm' with the fully qualified name of the form builder.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 hours ago

























          answered 8 hours ago









          kiamlalunokiamlaluno

          80.6k9132249




          80.6k9132249












          • This is a good point, but this is the same for FormAjaxException. I think if core succeeds to control the code flow of the Form API without exceptions (which is very unlikely to happen before Drupal 9), it wouldn't affect much of custom code.

            – 4k4
            7 hours ago











          • Actually, the patch for that issue removes the part handling an instance of a class extending the Response class and it forces form builders to return an array from their buildForm() method.

            – kiamlaluno
            6 hours ago











          • This patch is from 2015 when core maintainers were more ambitious to remove exceptions for code flow control. We don't know what they will decide if this issue is picked up again and they might consider a replacement for redirecting in form builders directly.

            – 4k4
            6 hours ago











          • The point is not removing an exception. In fact, the code would still throw an exception, if that patch would be committed to Drupal core.

            – kiamlaluno
            5 hours ago











          • Why should the patch be committed after four years when there is no reason for it anymore since the introduction of EnforcedResponseException? There is of course the point "Exceptions should not be used for code flow control." If this is resolved the patch might be revisited, but probably in a different form and by having a solution to rewrite existing code if necessary.

            – 4k4
            4 hours ago


















          • This is a good point, but this is the same for FormAjaxException. I think if core succeeds to control the code flow of the Form API without exceptions (which is very unlikely to happen before Drupal 9), it wouldn't affect much of custom code.

            – 4k4
            7 hours ago











          • Actually, the patch for that issue removes the part handling an instance of a class extending the Response class and it forces form builders to return an array from their buildForm() method.

            – kiamlaluno
            6 hours ago











          • This patch is from 2015 when core maintainers were more ambitious to remove exceptions for code flow control. We don't know what they will decide if this issue is picked up again and they might consider a replacement for redirecting in form builders directly.

            – 4k4
            6 hours ago











          • The point is not removing an exception. In fact, the code would still throw an exception, if that patch would be committed to Drupal core.

            – kiamlaluno
            5 hours ago











          • Why should the patch be committed after four years when there is no reason for it anymore since the introduction of EnforcedResponseException? There is of course the point "Exceptions should not be used for code flow control." If this is resolved the patch might be revisited, but probably in a different form and by having a solution to rewrite existing code if necessary.

            – 4k4
            4 hours ago

















          This is a good point, but this is the same for FormAjaxException. I think if core succeeds to control the code flow of the Form API without exceptions (which is very unlikely to happen before Drupal 9), it wouldn't affect much of custom code.

          – 4k4
          7 hours ago





          This is a good point, but this is the same for FormAjaxException. I think if core succeeds to control the code flow of the Form API without exceptions (which is very unlikely to happen before Drupal 9), it wouldn't affect much of custom code.

          – 4k4
          7 hours ago













          Actually, the patch for that issue removes the part handling an instance of a class extending the Response class and it forces form builders to return an array from their buildForm() method.

          – kiamlaluno
          6 hours ago





          Actually, the patch for that issue removes the part handling an instance of a class extending the Response class and it forces form builders to return an array from their buildForm() method.

          – kiamlaluno
          6 hours ago













          This patch is from 2015 when core maintainers were more ambitious to remove exceptions for code flow control. We don't know what they will decide if this issue is picked up again and they might consider a replacement for redirecting in form builders directly.

          – 4k4
          6 hours ago





          This patch is from 2015 when core maintainers were more ambitious to remove exceptions for code flow control. We don't know what they will decide if this issue is picked up again and they might consider a replacement for redirecting in form builders directly.

          – 4k4
          6 hours ago













          The point is not removing an exception. In fact, the code would still throw an exception, if that patch would be committed to Drupal core.

          – kiamlaluno
          5 hours ago





          The point is not removing an exception. In fact, the code would still throw an exception, if that patch would be committed to Drupal core.

          – kiamlaluno
          5 hours ago













          Why should the patch be committed after four years when there is no reason for it anymore since the introduction of EnforcedResponseException? There is of course the point "Exceptions should not be used for code flow control." If this is resolved the patch might be revisited, but probably in a different form and by having a solution to rewrite existing code if necessary.

          – 4k4
          4 hours ago






          Why should the patch be committed after four years when there is no reason for it anymore since the introduction of EnforcedResponseException? There is of course the point "Exceptions should not be used for code flow control." If this is resolved the patch might be revisited, but probably in a different form and by having a solution to rewrite existing code if necessary.

          – 4k4
          4 hours ago












          0














          yes, you are right. you can redirect to the node using the code that you have mentioned. There is another way to set the redirection check the below code.



          use the name space :



           
          use SymfonyComponentHttpFoundationRedirectResponse;
          $response = new RedirectResponse(node url);
          $response->send();
          exit(0);


          I don't know what you are trying to achieve hope this code may help you.






          share|improve this answer


















          • 1





            exits should not be needed

            – Kevin
            9 hours ago











          • @Kevin is correct: exit() should not be used.

            – kiamlaluno
            8 hours ago
















          0














          yes, you are right. you can redirect to the node using the code that you have mentioned. There is another way to set the redirection check the below code.



          use the name space :



           
          use SymfonyComponentHttpFoundationRedirectResponse;
          $response = new RedirectResponse(node url);
          $response->send();
          exit(0);


          I don't know what you are trying to achieve hope this code may help you.






          share|improve this answer


















          • 1





            exits should not be needed

            – Kevin
            9 hours ago











          • @Kevin is correct: exit() should not be used.

            – kiamlaluno
            8 hours ago














          0












          0








          0







          yes, you are right. you can redirect to the node using the code that you have mentioned. There is another way to set the redirection check the below code.



          use the name space :



           
          use SymfonyComponentHttpFoundationRedirectResponse;
          $response = new RedirectResponse(node url);
          $response->send();
          exit(0);


          I don't know what you are trying to achieve hope this code may help you.






          share|improve this answer













          yes, you are right. you can redirect to the node using the code that you have mentioned. There is another way to set the redirection check the below code.



          use the name space :



           
          use SymfonyComponentHttpFoundationRedirectResponse;
          $response = new RedirectResponse(node url);
          $response->send();
          exit(0);


          I don't know what you are trying to achieve hope this code may help you.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 12 hours ago









          sekharctcsekharctc

          214




          214







          • 1





            exits should not be needed

            – Kevin
            9 hours ago











          • @Kevin is correct: exit() should not be used.

            – kiamlaluno
            8 hours ago













          • 1





            exits should not be needed

            – Kevin
            9 hours ago











          • @Kevin is correct: exit() should not be used.

            – kiamlaluno
            8 hours ago








          1




          1





          exits should not be needed

          – Kevin
          9 hours ago





          exits should not be needed

          – Kevin
          9 hours ago













          @Kevin is correct: exit() should not be used.

          – kiamlaluno
          8 hours ago






          @Kevin is correct: exit() should not be used.

          – kiamlaluno
          8 hours ago


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Drupal Answers!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f277594%2fhow-to-to-redirect-a-form-to-a-certain-node-for-anonymous-users%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Era Viking Índice Início da Era Viquingue | Cotidiano | Sociedade | Língua | Religião | A arte | As primeiras cidades | As viagens dos viquingues | Viquingues do Oeste e Leste | Fim da Era Viquingue | Fontes históricas | Referências Bibliografia | Ligações externas | Menu de navegação«Sverige då!»«Handel I vikingetid»«O que é Nórdico Antigo»Mito, magia e religião na volsunga saga Um olhar sobre a trajetória mítica do herói sigurd«Bonden var den verklige vikingen»«Vikingatiden»«Vikingatiden»«Vinland»«Guerreiras de Óðinn: As Valkyrjor na Mitologia Viking»1519-9053«Esculpindo símbolos e seres: A arte viking em pedras rúnicas»1679-9313Historia - Tema: VikingarnaAventura e Magia no Mundo das Sagas IslandesasEra Vikinge

          What's the metal clinking sound at the end of credits in Avengers: Endgame?What makes Thanos so strong in Avengers: Endgame?Who is the character that appears at the end of Endgame?What happens to Mjolnir (Thor's hammer) at the end of Endgame?The People's Ages in Avengers: EndgameWhat did Nebula do in Avengers: Endgame?Messing with time in the Avengers: Endgame climaxAvengers: Endgame timelineWhat are the time-travel rules in Avengers Endgame?Why use this song in Avengers: Endgame Opening Logo Sequence?Peggy's age in Avengers Endgame

          Are there legal definitions of ethnicities/races? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Legal definitions in the United StatesAre there truly legal limits on US interest rates?Are gender identity and sexual orientation federally protected?Why is there an apparent legal bias against digital services?What limits are there to the powers of individual judges in the United States legal system?Are women only scholarships legal under Irish / EU law?Is the term “race” defined by Public Law enacted by Congress of the United StatesIs there a legal definition of race in the US?Neighbors are spying for landlord on Renters is it legal?Are Protected Classes Bi-directional?