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);
Comments
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
Add new comment