Skip to content

Commit 926b7d3

Browse files
committed
[#2092] Tweaks thanks to @bschussek
1 parent adf8989 commit 926b7d3

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

book/forms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ controller::
226226
.. versionadded:: 2.3
227227
The :method:`Symfony\Component\Form\FormInterface::handleRequest` method was
228228
added in Symfony 2.3. Previously, the now-deprecated ``bind`` function
229-
was used. For details on that method, see :doc:`/cookbook/form/deprecated_bind`.
229+
was used. For details on that method, see :doc:`/cookbook/form/direct_bind`.
230230

231231
This controller follows a common pattern for handling forms, and has three
232232
possible paths:

cookbook/doctrine/registration_form.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ and its template:
251251
{# src/Acme/AccountBundle/Resources/views/Account/register.html.twig #}
252252
{{ form(form) }}
253253

254-
Finally, create the controller (and corresponding ``account_create``) which
255-
handles the form submission. This performs the validation and saves the data
256-
into the database::
254+
Finally, create the controller (and the corresponding route ``account_create``)
255+
which handles the form submission. This performs the validation and saves
256+
the data into the database::
257257

258258
public function createAction(Request $request)
259259
{

cookbook/form/deprecated_bind.rst renamed to cookbook/form/direct_bind.rst

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. index::
2-
single: Form; Form testing
2+
single: Form; Form::bind
33

4-
How to use the (deprecated) bind Function to handle Form Submissions
5-
====================================================================
4+
How to use the bind Function to handle Form Submissions
5+
=======================================================
66

77
In Symfony 2.3, a new :method:`Symfony\Component\Form\FormInterface::handleRequest`
88
method was added, which makes handling form submissions easier than ever::
@@ -33,6 +33,9 @@ method was added, which makes handling form submissions easier than ever::
3333

3434
To see more about this method, read :ref:`book-form-handling-form-submissions`.
3535

36+
Using Form::bind() to handle a request (deprecated)
37+
---------------------------------------------------
38+
3639
Prior to this, the :method:`Symfony\Component\Form\FormInterface::bind` method
3740
was used instead::
3841

@@ -60,4 +63,38 @@ was used instead::
6063
));
6164
}
6265

63-
This still works, but is deprecated and will be removed in Symfony 3.0.
66+
Passing the :class:`Symfony\\Component\HttpFoundation\\Request` directly to
67+
``bind`` still works, but is deprecated and will be removed in Symfony 3.0.
68+
However, you *can* safely pass array values directly to bind.
69+
70+
Passing an Array directly to Form::bind
71+
---------------------------------------
72+
73+
In some cases, you may want to collect and pass an array of values directly
74+
to a Form, instead of using the ``handleRequest`` method. This is absolutely
75+
valid and not deprecated (passing a :class:`Symfony\\Component\HttpFoundation\\Request`
76+
object to ``Form::bind`` is deprecated, but passing an array of ok)::
77+
78+
use Symfony\Component\HttpFoundation\Request;
79+
// ...
80+
81+
public function newAction(Request $request)
82+
{
83+
$form = $this->createFormBuilder()
84+
// ...
85+
->getForm();
86+
87+
if ($request->isMethod('POST')) {
88+
$form->bind($request->request->get($form->getName()));
89+
90+
if ($form->isValid()) {
91+
// perform some action...
92+
93+
return $this->redirect($this->generateUrl('task_success'));
94+
}
95+
}
96+
97+
return $this->render('AcmeTaskBundle:Default:new.html.twig', array(
98+
'form' => $form->createView(),
99+
));
100+
}

cookbook/form/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Form
1313
use_virtuals_forms
1414
unit_testing
1515
use_empty_data
16-
deprecated_bind
16+
direct_bind

cookbook/map.rst.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
* :doc:`/cookbook/form/use_virtuals_forms`
8888
* :doc:`/cookbook/form/unit_testing`
8989
* :doc:`/cookbook/form/use_empty_data`
90-
* :doc:`/cookbook/form/deprecated_bind`
90+
* :doc:`/cookbook/form/direct_bind`
9191
* (validation) :doc:`/cookbook/validation/custom_constraint`
9292
* (doctrine) :doc:`/cookbook/doctrine/file_uploads`
9393

0 commit comments

Comments
 (0)