11..index ::
2- single: Form; Form::bind
2+ single: Form; Form::submit()
33
4- How to use thebind Function to handle Form Submissions
5- =======================================================
4+ How to use thesubmit() Function to handle Form Submissions
5+ ===========================================================
66
77In Symfony 2.3, a new:method: `Symfony\C omponent\F orm\F ormInterface::handleRequest `
88method was added, which makes handling form submissions easier than ever::
@@ -33,11 +33,14 @@ 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- ---------------------------------------------------
36+ Calling Form::submit ()manually
37+ -------------------------------
3838
39- Prior to this, the:method: `Symfony\C omponent\F orm\F ormInterface::bind ` method
40- was used instead::
39+ In some cases, you want better control over when exactly your form is submitted
40+ and what data is passed to it. Instead of using the
41+ :method: `Symfony\C omponent\F orm\F ormInterface::handleRequest `
42+ method, pass the submitted data directly to
43+ :method: `Symfony\C omponent\F orm\F ormInterface::submit `::
4144
4245 use Symfony\Component\HttpFoundation\Request;
4346 // ...
@@ -49,7 +52,7 @@ was used instead::
4952 ->getForm();
5053
5154 if ($request->isMethod('POST')) {
52- $form->bind ($request);
55+ $form->submit ($request->request->get($form->getName()) );
5356
5457 if ($form->isValid()) {
5558 // perform some action...
@@ -63,17 +66,21 @@ was used instead::
6366 ));
6467 }
6568
66- Passing the:class: `Symfony\\ Component\H ttpFoundation\\ 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+ ..tip ::
70+
71+ Forms consisting of nested fields expect an array in
72+ :method: `Symfony\C omponent\F orm\F ormInterface::submit `. You can also submit
73+ individual fields by calling:method: `Symfony\C omponent\F orm\F ormInterface::submit `
74+ directly on the field::
6975
70- Passing an Array directly to Form::bind
71- ---------------------------------------
76+ $form->get('firstName')->submit('Fabien');
7277
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\H ttpFoundation\\ Request `
76- object to ``Form::bind `` is deprecated, but passing an array of ok)::
78+ Passing a Request to Form::submit() (deprecated)
79+ ------------------------------------------------
80+
81+ Before Symfony 2.3, the:method: `Symfony\C omponent\F orm\F ormInterface::submit `
82+ method accepted a:class: `Symfony\\ Component\\ HttpFoundation\\ Reuqest ` object as
83+ a convenient shortcut to the previous example::
7784
7885 use Symfony\Component\HttpFoundation\Request;
7986 // ...
@@ -85,7 +92,7 @@ object to ``Form::bind`` is deprecated, but passing an array of ok)::
8592 ->getForm();
8693
8794 if ($request->isMethod('POST')) {
88- $form->bind ($request->request->get($form->getName()) );
95+ $form->submit ($request);
8996
9097 if ($form->isValid()) {
9198 // perform some action...
@@ -98,3 +105,8 @@ object to ``Form::bind`` is deprecated, but passing an array of ok)::
98105 'form' => $form->createView(),
99106 ));
100107 }
108+
109+ Passing the:class: `Symfony\\ Component\H ttpFoundation\\ Request ` directly to
110+ :method: `Symfony\\ Component\\ Form\\ FormInterface::submit` ` still works, but is
111+ deprecated and will be removed in Symfony 3.0. You should use the method
112+ :method: `Symfony\C omponent\F orm\F ormInterface::handleRequest ` instead.