8000 Merge pull request #758 from mdpatrick/form_request_obj_tip · GromNaN/symfony-docs@b0204df · GitHub
[go: up one dir, main page]

Skip to content

Commit b0204df

Browse files
committed
Merge pull request symfony#758 from mdpatrick/form_request_obj_tip
Form request obj tip
2 parents 5367768 + 12805e2 commit b0204df

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

book/forms.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,18 @@ an array. In this example, since ``$defaultData`` is not an object (and
13611361
no ``data_class`` option is set), ``$form->getData()`` ultimately returns
13621362
an array.
13631363

1364+
.. tip::
1365+
You can also access POST values (in this case "name") directly through
1366+
the request object, like so:
1367+
1368+
.. code-block:: php
1369+
$this->get('request')->request->get('name');
1370+
1371+
Be advised, however, that in most cases using the getData() method is
1372+
a better choice, because it reduces the confusion inherent with having
1373+
to sort out the form's characteristically unique namespace in order access
1374+
the form's data array.
1375+
13641376
Adding Validation
13651377
~~~~~~~~~~~~~~~~~
13661378

0 commit comments

Comments
 (0)
0