0

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(/* ... */);
}
D4V1D
  • 5,805
  • 3
  • 30
  • 65
Max Lipsky
  • 1,774
  • 1
  • 18
  • 29
  • 4
    `redirect()` so you can't resubmit the form by refreshing the page. – D4V1D Nov 26 '15 at 08:11
  • 3
    Possible duplicate of [Difference between $this->render and $this->redirect Symfony2](http://stackoverflow.com/questions/9442533/difference-between-this-render-and-this-redirect-symfony2) – D4V1D Nov 26 '15 at 08:12

1 Answers1

6

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).

Victor Bocharsky
  • 11,930
  • 13
  • 58
  • 91