By editor, 15 January, 2016 Question How to redirect a form after submission Example : (Insert this line in to your form submitForm() methode) Redirect to the user page ( Redirection on form submit) $form_state->setRedirect('user.page'); Redirect to a custom page $form_state->setRedirect('your.module.route.name'); Like: public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->setRedirect('your.module.route.name'); } Using a Url Object (use Drupal\Core\Url) $url = Url::fromRoute('route.name', [ 'arg1' => "value1", 'arg1' => "value2", ]); $form_state->setRedirectUrl($url); Tags Drupal 8 Code Form Add new comment Tips for Form API of Drupal 8 Page Redirection on Drupal 8 / 9 Redirect a user after login. Redirection on Drupal 8. Comments4 You must have JavaScript enabled to use this form. Your name Subject Comment About text formats Plain text No HTML tags allowed. Lines and paragraphs break automatically. Web page addresses and email addresses turn into links automatically. Redirect to a custom page Greetings, If i want to redirect a form to a view page? how can i do that? $form_state->setRedirect('views.route.name'); ? how would i get the route name? can you please help? Thanks Reply You can use page redirection… You can use page redirection like: return new \Symfony\Component\HttpFoundation\RedirectResponse(\Drupal::url('user.page')); Page Redirection on Drupal 8 Reply When i use $form_state-… When i use $form_state->setRedirect('<front>'); i get nothing in $_POST array on front page. How can i send post data of form with setRedirect? Reply page redirection how to redirect node Reply
Redirect to a custom page Greetings, If i want to redirect a form to a view page? how can i do that? $form_state->setRedirect('views.route.name'); ? how would i get the route name? can you please help? Thanks Reply
You can use page redirection… You can use page redirection like: return new \Symfony\Component\HttpFoundation\RedirectResponse(\Drupal::url('user.page')); Page Redirection on Drupal 8 Reply
When i use $form_state-… When i use $form_state->setRedirect('<front>'); i get nothing in $_POST array on front page. How can i send post data of form with setRedirect? Reply
Comments4
Redirect to a custom page
Greetings,
If i want to redirect a form to a view page? how can i do that?
$form_state->setRedirect('views.route.name'); ? how would i get the route name?
can you please help? Thanks
You can use page redirection…
You can use page redirection like:
return new \Symfony\Component\HttpFoundation\RedirectResponse(\Drupal::url('user.page'));
Page Redirection on Drupal 8
When i use $form_state-…
When i use
$form_state->setRedirect('<front>');
i get nothing in $_POST array on front page. How can i send post data of form with setRedirect?page redirection
how to redirect node