Reputation: 1842
What is better? Returned redirect or to make render after successful submit form?
Redirect:
public function newAction(Request $request)
{
// ...
if ($form->isValid()) {
return $this->redirect(/* ... */);
}
return $this->render(/* ... */);
}
Second:
public function newAction(Request $request)
{
// ...
if ($form->isValid()) {
return $this->render(/* ... */);
}
return $this->render(/* ... */);
}
Upvotes: 0
Views: 97
Reputation: 12306
If a form was sent via POST
method - the best way is to redirect a user to the some page (for example, to the list of entities). It prevents resubmitting form by a user again.
Better use
redirectToRoute()
method for Symfony>=2.6
But if you work with GET
method - you definitely want to use render()
method (for example, in order to display some filtering entities or data based on your GET-query).
Upvotes: 6