From a351d8ad660e9bdf4319af58d933919e97bfe6bb Mon Sep 17 00:00:00 2001 From: Wouter J Date: Sat, 19 Sep 2015 14:22:32 +0200 Subject: [PATCH] Added caution to call createView after handleRequest --- book/forms.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/book/forms.rst b/book/forms.rst index ca018db346f..38f163aa27b 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -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