Skip to content

Commit

Permalink
minor #5708 Added caution to call createView after handleRequest (Wou…
Browse files Browse the repository at this point in the history
…terJ)

This PR was merged into the 2.3 branch.

Discussion
----------

Added caution to call createView after handleRequest

| Q | A
| --- | ---
| Doc fix? | yes
| New docs? | yes
| Applies to | all
| Fixed tickets | -

Many thanks to *sidi* on IRC for catching this missing important information!

Commits
-------

a351d8a Added caution to call createView after handleRequest
  • Loading branch information
xabbuh committed Oct 3, 2015
2 parents 917e6ca + a351d8a commit 790e2c0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,21 @@ controller::
$form->handleRequest($request);

if ($form->isValid()) {
// perform some action, such as saving the task to the database
// ... perform some action, such as saving the task to the database

return $this->redirect($this->generateUrl('task_success'));
}

// ...
return $this->render('default/new.html.twig', array(
'form' => $form->createView(),
));
}
.. caution::

Be aware that the ``createView()`` method should be called *after* ``handleRequest``
is called. Otherwise, changes done in the ``*_SUBMIT`` events aren't applied to the
view (like validation errors).

.. versionadded:: 2.3
The :method:`Symfony\\Component\\Form\\FormInterface::handleRequest` method
Expand Down

0 comments on commit 790e2c0

Please sign in to comment.