I want to redirect to a route and also want to send some parameters which I don't want to expose on URL.

So, I need to redirect with a post method. How to do this?

$form_state->setRedirect('route.name', array('key' => 'value'));
new RedirectResponse(\Drupal::url('route.name',array('key' => 'value')));

all these above procedure to redirect is done through GET methods.

So, is it possible to do this with POST method?


1 Answer 1


Normally, you cannot redirect through a HTTP "POST" response. A normal Drupal RedirectResponse (or whatever redirect response you send) will be a 302 or 301 redirect, which is done through the GET method.

Basically, you can do a subrequest, as suggested by Eyal, or you can add some server validation to grant a "200 OK" response through your "hidden" route, such as a CSRF token. To keep alive some posted information, you can use your Session service to flash them for the next request, then flush them in your hidden route after your validation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.