Reputation: 57
I have a weird problem. I want to setAction to form to redirect to another controller. I have 2 controllers for user and address. On route /{id}/modify we are in users controller twig and there is this, generated form:
$add=new Address();
$formAddress=$this->createFormBuilder($add)
->setAction($this->redirectToRoute("/{id}/addAddress",array('id'=>$id)))
->add("city","text")
->add("street","text")
->add("housenumber","text")
->add("flatnumber","text")
->add("send","submit")
->getForm();
After submitting I want to be redirected to address controller where form will be handled, route of address controller is /{id}/addAddress. Thanks in advance for answers! Cheers!
Upvotes: 4
Views: 4404
Reputation: 27295
Your action is not correct. If you use the function redirectToRoute
it expect a route name.
// redirect to a route with parameters
return $this->redirectToRoute('blog_show', array('slug' => 'my-page'));
The first parameter (string) is the name for the route you try to send your form to. Otherwise you have to use redirect and use generateUrl
to get the url which does the same but redirectToUrl
is newer a shorter.
https://symfony.com/doc/current/controller.html
Upvotes: 3