Skip to content

Commit a351d8a

Browse files
committed
Added caution to call createView after handleRequest
1 parent 17bb0fc commit a351d8a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

book/forms.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,21 @@ controller::
232232
$form->handleRequest($request);
233233

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

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

240-
// ...
240+
return $this->render('default/new.html.twig', array(
241+
'form' => $form->createView(),
242+
));
241243
}
244+
245+
.. caution::
246+
247+
Be aware that the ``createView()`` method should be called *after* ``handleRequest``
248+
is called. Otherwise, changes done in the ``*_SUBMIT`` events aren't applied to the
249+
view (like validation errors).
242250

243251
.. versionadded:: 2.3
244252
The :method:`Symfony\\Component\\Form\\FormInterface::handleRequest` method

0 commit comments

Comments
 (0)