Skip to content

Commit 068a17f

Browse files
committed
fixed typos in the Form chapter
1 parent 6447df3 commit 068a17f

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

guides/forms.rst

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Your First Form
1111
---------------
1212

1313
A form in Symfony2 is a transparent layer on top of your domain model. It
14-
reads properties from an object, displays the values in the form and allows
14+
reads properties from an object, displays the values in the form, and allows
1515
the user to change them. When the form is submitted, the values are written
1616
back into the object.
1717

@@ -21,7 +21,6 @@ Let's see how this works in a practical example. Let's create a simple
2121
class Customer
2222
{
2323
public $name;
24-
2524
private $age = 20;
2625

2726
public function getAge()
@@ -34,9 +33,9 @@ Let's see how this works in a practical example. Let's create a simple
3433
$this->age = $age;
3534
}
3635
}
37-
38-
The class contains two properties ``name`` and "age". The property ``$name`` is
39-
public, while ``$age`` can only be modified through setters and getters.
36+
37+
The class contains two properties ``name`` and "age". The property ``$name``
38+
is public, while ``$age`` can only be modified through setters and getters.
4039

4140
Now let's create a form to let the visitor fill the data of the object::
4241

@@ -49,12 +48,12 @@ Now let's create a form to let the visitor fill the data of the object::
4948
$form->add(new TextField('name'));
5049
$form->add(new IntegerField('age'));
5150

52-
return $this->render('HelloBundle:Hello:signup', array('form' => $form));
51+
return $this->render('HelloBundle:Hello:signup.php', array('form' => $form));
5352
}
54-
53+
5554
A form consists of various fields. Each field represents a property in your
5655
class. The property must have the same name as the field and must either be
57-
public or accessible through public getters and setters. Now let's create a
56+
public or accessible through public getters and setters. Now let's create a
5857
simple template to render the form:
5958

6059
.. code-block:: html+php
@@ -67,9 +66,9 @@ simple template to render the form:
6766
<?php echo $form->render() ?>
6867
<input type="submit" value="Send!" />
6968
</form>
70-
71-
When the user submits the form, we also need to handle the submitted data.
72-
All the data is stored in a POST parameter with the name of the form::
69+
70+
When the user submits the form, we also need to handle the submitted data. All
71+
the data is stored in a POST parameter with the name of the form::
7372

7473
# src/Application/HelloBundle/Controller/HelloController.php
7574
public function signupAction()
@@ -79,17 +78,17 @@ All the data is stored in a POST parameter with the name of the form::
7978

8079
// form setup...
8180

82-
if ($this['request']->getMethod() == 'POST') {
83-
$form->bind($this['request']->getParameter('customer'));
81+
if ('POST' === $this['request']->getMethod()) {
82+
$form->bind($this['request']->request->get('customer'));
8483

8584
if ($form->isValid()) {
8685
// save $customer object and redirect
8786
}
8887
}
8988

90-
return $this->render('HelloBundle:Hello:signup', array('form' => $form));
89+
return $this->render('HelloBundle:Hello:signup.php', array('form' => $form));
9190
}
92-
91+
9392
Congratulations! You just created your first fully-functional form with
9493
Symfony2.
9594

@@ -99,15 +98,17 @@ Symfony2.
9998
Form Fields
10099
-----------
101100

102-
As you have learned, a form consists of one or more form fields. In Symfony2,
101+
As you have learned, a form consists of one or more form fields. In Symfony2,
103102
form fields have two responsibilities:
104103

105-
* Render HTML
106-
* Convert data between normalized and humane representations
104+
* Render HTML;
105+
106+
* Convert data between normalized and humane representations.
107107

108-
Let's look at the ``DateField`` for example. While you probably prefer to store
109-
dates as strings or ``DateTime`` objects, users rather like to choose them from a
110-
list of drop downs. ``DateField`` handles the rendering and type conversion for you.
108+
Let's look at the ``DateField`` for example. While you probably prefer to
109+
store dates as strings or ``DateTime`` objects, users rather like to choose
110+
them from a list of drop downs. ``DateField`` handles the rendering and type
111+
conversion for you.
111112

112113
Basic Fields
113114
~~~~~~~~~~~~
@@ -186,16 +187,16 @@ at the same time::
186187

187188
// process form ...
188189
}
189-
190+
190191
With only these little changes you can now edit also the ``Address`` object!
191192
Cool, ey?
192193

193194
Repeated Fields
194195
~~~~~~~~~~~~~~~
195196

196-
The ``RepeatedField`` is an extended field group that allows you to output a field
197-
twice. The repeated field will only validate if the user enters the same value
198-
in both fields::
197+
The ``RepeatedField`` is an extended field group that allows you to output a
198+
field twice. The repeated field will only validate if the user enters the same
199+
value in both fields::
199200

200201
$form->add(new RepeatedField(new TextField('email')));
201202

@@ -205,7 +206,7 @@ Collection Fields
205206
~~~~~~~~~~~~~~~~~
206207

207208
The ``CollectionField`` is a special field group for manipulating arrays or
208-
objects that implement the interface ``Traversable``. To demonstrate this, we
209+
objects that implement the interface ``Traversable``. To demonstrate this, we
209210
will extend the ``Customer`` class to store three email addresses::
210211

211212
class Customer
@@ -219,9 +220,9 @@ We will now add a ``CollectionField`` to manipulate these addresses::
219220

220221
$form->add(new CollectionField(new TextField('emails')));
221222

222-
If you set the option "modifiable" to ``true``, you can even add or remove rows
223-
in the collection via Javascript! The ``CollectionField`` will notice it and
224-
resize the underlying array accordingly.
223+
If you set the option "modifiable" to ``true``, you can even add or remove
224+
rows in the collection via Javascript! The ``CollectionField`` will notice it
225+
and resize the underlying array accordingly.
225226

226227
.. index::
227228
single: Forms; Validation
@@ -230,7 +231,7 @@ Form Validation
230231
---------------
231232

232233
You have already learned in the last part of this tutorial how to set up
233-
validation constraints for a PHP class. The nice thing is that this is enough
234+
validation constraints for a PHP class. The nice thing is that this is enough
234235
to validate a Form! Remember that a form is nothing more than a gateway for
235236
changing data in an object.
236237

@@ -275,19 +276,19 @@ Now we can easily adapt the form in the controller::
275276

276277
$form->add($group);
277278

278-
if ($this['request']->getMethod() == 'POST') {
279-
$form->bind($this['request']->getParameter('customer'));
279+
if ('POST' === $this['request']->getMethod()) {
280+
$form->bind($this['request']->request->get('customer'));
280281

281282
if ($form->isValid()) {
282283
$registration->process();
283284
}
284285
}
285286

286-
return $this->render('HelloBundle:Hello:signup', array('form' => $form));
287+
return $this->render('HelloBundle:Hello:signup.php', array('form' => $form));
287288
}
288-
289+
289290
The big benefit of this refactoring is that we can reuse the ``Registration``
290-
class. Extending the application to allow users to sign up via XML is no
291+
class. Extending the application to allow users to sign up via XML is no
291292
problem at all!
292293

293294
.. index::
@@ -296,11 +297,11 @@ problem at all!
296297
Customizing the View
297298
--------------------
298299

299-
Unfortunately the output of ``$form->render()`` doesn't look too great. Symfony
300-
2.0 makes it very easy though to customize the HTML of a form. You can access
301-
every field and field group in the form by its name. All fields offer the
302-
method ``render()`` for rendering the widget and ``renderErrors()`` for rendering
303-
a ``<ul>``-list with the field errors.
300+
Unfortunately the output of ``$form->render()`` doesn't look too great.
301+
Symfony 2.0 makes it very easy though to customize the HTML of a form. You can
302+
access every field and field group in the form by its name. All fields offer
303+
the method ``render()`` for rendering the widget and ``renderErrors()`` for
304+
rendering a ``<ul>``-list with the field errors.
304305

305306
The following example shows you how to refine the HTML of an individual form
306307
field::
@@ -333,8 +334,8 @@ for your hidden fields:
333334
<div class="form-row">
334335
...
335336
</div>
336-
<?php endif ?>
337-
<?php endforeach ?>
337+
<?php endif; ?>
338+
<?php endforeach; ?>
338339

339340
By using plain HTML, you have the greatest possible flexibility in designing
340341
your forms. Especially your designers will be happy that they can manipulate
@@ -346,6 +347,6 @@ Final Thoughts
346347
This chapter showed you how the Form component of Symfony2 can help you to
347348
rapidly create forms for your domain objects. The component embraces a strict
348349
separation between business logic and presentation. Many fields are
349-
automatically localized to make your visitors feel comfortable on your website.
350-
And with the new architecture, this is just the beginning of many new, mighty
351-
user-created fields!
350+
automatically localized to make your visitors feel comfortable on your
351+
website. And with the new architecture, this is just the beginning of many
352+
new, mighty user-created fields!

0 commit comments

Comments
 (0)