@@ -9,7 +9,7 @@ The Form Component
99 forms.
1010
1111The form component is a tool to help you solve the problem of allowing end-users
12- to interact with the data and modify the data in your application. And thought
12+ to interact with the data and modify the data in your application. And though
1313traditionally this has been through HTML forms, the component focuses on
1414processing data to and from your client and application, whether that data
1515be from a normal form post or from an API.
@@ -155,7 +155,7 @@ line to your ``composer.json`` file:
155155 }
156156 }
157157
158- The TwigBridge integration provides you with several :doc: `Twig Functions</reference/forms/twig_reference `
158+ The TwigBridge integration provides you with several :doc: `Twig Functions</reference/forms/twig_reference> `
159159that help you render each the HTML widget, label and error for each field
160160(as well as a few other things). To configure the integration, you'll need
161161to bootstrap or access Twig and add the :class: `Symfony\\ Bridge\\ Twig\\ Extension\\ FormExtension `::
@@ -267,8 +267,8 @@ Validation
267267
268268The Form component comes with tight (but optional) integration with Symfony's
269269Validator component. If you're using a different solution for validation,
270- no problem! Simply take the bound data of your form (which is an array or
271- object) and pass it through your own validation system.
270+ no problem! Simply take the submitted/ bound data of your form (which is an
271+ array or object) and pass it through your own validation system.
272272
273273To use the integration with Symfony's Validator component, first make sure
274274it's installed in your application. If you're using Composer and want to
@@ -302,8 +302,18 @@ Your integration with the Validation component will look something like this::
302302 $validator = Validation::createValidator();
303303
304304 // there are built-in translations for the core error messages
305- $translator->addResource('xlf', VENDOR_FORM_DIR . '/Resources/translations/validators.en.xlf', 'en', 'validators');
306- $translator->addResource('xlf', VENDOR_VALIDATOR_DIR . '/Resources/translations/validators.en.xlf', 'en', 'validators');
305+ $translator->addResource(
306+ 'xlf',
307+ VENDOR_FORM_DIR . '/Resources/translations/validators.en.xlf',
308+ 'en',
309+ 'validators'
310+ );
311+ $translator->addResource(
312+ 'xlf',
313+ VENDOR_VALIDATOR_DIR . '/Resources/translations/validators.en.xlf',
314+ 'en',
315+ 'validators'
316+ );
307317
308318 $formFactory = Forms::createFormFactoryBuilder()
309319 // ...
@@ -320,6 +330,12 @@ should be used to create any and all form objects in your application. This
320330means that you should create it in some central, bootstrap part of your application
321331and then access it whenever you need to build a form.
322332
333+ .. note ::
334+
335+ In this document, the form factory is always a locally variable called
336+ ``$formFactory ``. The point here is that you will probably need to create
337+ this object in some more "global" way so you can access it from anywhere.
338+
323339Exactly how you gain access to your one form factory is up to you. If you're
324340using a :term`Service Container`, then you should add the form factory to
325341your container and grab it out whenever you need to. If your application
@@ -373,7 +389,7 @@ is created from the form factory.
373389 public function newAction(Request $request)
374390 {
375391 // createFormBuilder is a shortcut to get the "form factory"
376- // and then call "createBuilder" on it
392+ // and then call "createBuilder() " on it
377393 $form = $this->createFormBuilder()
378394 ->add('task', 'text')
379395 ->add('dueDate', 'date')
@@ -388,7 +404,7 @@ is created from the form factory.
388404 As you can see, creating a form is like writing a recipe: you call ``add ``
389405for each new field you want to create. The first argument to ``add `` is the
390406name of your field, and the second is the field "type". The Form component
391- comes with a lot of :ref : `built-in types</reference/forms/types> `.
407+ comes with a lot of :doc : `built-in types</reference/forms/types> `.
392408
393409Now that you've built your form, learn how to :ref: `render<component-form-intro-rendering-form> `
394410it and :ref: `process the form submission<component-form-intro-handling-submission> `.
@@ -507,6 +523,7 @@ method:
507523 ->add('dueDate', 'date')
508524 ->getForm();
509525
526+ // only process the form if the request is a POST request
510527 if ($request->isMethod('POST')) {
511528 $form->bind($request);
512529
@@ -522,17 +539,20 @@ method:
522539 // ...
523540 }
524541
525- This defines a common form "workflow", which looks like this:
542+ This defines a common form "workflow", which contains 3 different possibilities:
543+
544+ 1) On the initial GET request (i.e. when the user "surfs" to your page),
545+ build your form and render it;
546+
547+ If the request is a POST, process the submitted data (via ``bind ``). Then:
526548
527- 1) Build your form;
528- 2) If POST, process the form by calling ``bind ``;
529- 3a) If the form is valid, perform some action and redirect;
530- 3b) If the form is invalid, re-render the form (which will now contain errors)
549+ 2) if the form is invalid, re-render the form (which will now contain errors)
550+ 3) if the form is valid, perform some action and redirect;
531551
532552.. note ::
533553
534554 If you're not using HttpFoundation, just pass the POST'ed data directly
535- to ``bind ``:
555+ to ``bind ``::
536556
537557 if (isset($_POST[$form->getName()])) {
538558 $form->bind($_POST[$form->getName())
@@ -598,3 +618,4 @@ and the errors will display next to the fields on error.
598618
599619.. _Packagist : https://packagist.org/packages/symfony/form
600620.. _Twig : http://twig.sensiolabs.org
621+ .. _`Twig Configuration` : http://twig.sensiolabs.org/doc/intro.html
0 commit comments