Skip to content

Commit 558966a

Browse files
committed
Merge branch 'master' of git://github.com/symfony/symfony-docs.git into docs_fix
2 parents 51deb99 + d037863 commit 558966a

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

guides/forms/overview.rst

100644100755
+25-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ the object.
1818
Let's see how this works in a practical example. Let's create a simple
1919
``Customer`` class::
2020

21+
namespace Application\HelloBundle\Entity;
22+
2123
class Customer
2224
{
2325
public $name;
@@ -40,6 +42,12 @@ is public, while ``$age`` can only be modified through setters and getters.
4042
Now let's create a form to let the visitor fill the data of the object::
4143

4244
// src/Application/HelloBundle/Controller/HelloController.php
45+
46+
use Application\HelloBundle\Entity\Customer;
47+
use Symfony\Component\Form\Form;
48+
use Symfony\Component\Form\TextField;
49+
use Symfony\Component\Form\IntegerField;
50+
4351
public function signupAction()
4452
{
4553
$customer = new Customer();
@@ -49,7 +57,7 @@ Now let's create a form to let the visitor fill the data of the object::
4957
$form->add(new IntegerField('age'));
5058

5159
return $this->render('HelloBundle:Hello:signup.php', array(
52-
'form' => $this->get('templating.form')->get($form)
60+
'form' => $form
5361
));
5462
}
5563

@@ -68,17 +76,15 @@ Let's create a simple template to render the form:
6876
# src/Application/HelloBundle/Resources/views/Hello/signup.php
6977
<?php $view->extend('HelloBundle::layout.php') ?>
7078

71-
<?php echo $form->form('#') ?>
72-
<?php echo $form->render() ?>
79+
<form action="#" method="post">
80+
<?php echo $view['form']->render($form) ?>
7381

7482
<input type="submit" value="Send!" />
7583
</form>
7684

7785
.. note::
7886

79-
Form rendering in templates is covered in two dedicated chapters: one for
80-
:doc:`PHP templates </guides/forms/view>`, and one for :doc:`Twig templates
81-
</guides/forms/twig>`.
87+
Form rendering in templates is covered in chapter :doc:`PHP templates </guides/forms/view>`.
8288

8389
When the user submits the form, we also need to handle the submitted data. All
8490
the data is stored in a POST parameter with the name of the form::
@@ -182,6 +188,9 @@ We can use a field group to show fields for the customer and the nested
182188
address at the same time::
183189

184190
# src/Application/HelloBundle/Controller/HelloController.php
191+
192+
use Symfony\Component\Form\FieldGroup;
193+
185194
public function signupAction()
186195
{
187196
$customer = new Customer();
@@ -207,6 +216,8 @@ The ``RepeatedField`` is an extended field group that allows you to output a
207216
field twice. The repeated field will only validate if the user enters the same
208217
value in both fields::
209218

219+
use Symfony\Component\Form\RepeatedField;
220+
210221
$form->add(new RepeatedField(new TextField('email')));
211222

212223
This is a very useful field for querying email addresses or passwords!
@@ -227,6 +238,8 @@ will extend the ``Customer`` class to store three email addresses::
227238

228239
We will now add a ``CollectionField`` to manipulate these addresses::
229240

241+
use Symfony\Component\Form\CollectionField;
242+
230243
$form->add(new CollectionField(new TextField('emails')));
231244

232245
If you set the option "modifiable" to ``true``, you can even add or remove
@@ -254,6 +267,8 @@ accepting terms and conditions.
254267

255268
Let's create a simple ``Registration`` class for this purpose::
256269

270+
namespace Application\HelloBundle\Entity;
271+
257272
class Registration
258273
{
259274
/** @validation:Valid */
@@ -271,6 +286,10 @@ Let's create a simple ``Registration`` class for this purpose::
271286
Now we can easily adapt the form in the controller::
272287

273288
# src/Application/HelloBundle/Controller/HelloController.php
289+
290+
use Application\HelloBundle\Entity\Registration;
291+
use Symfony\Component\Form\CheckboxField;
292+
274293
public function signupAction()
275294
{
276295
$registration = new Registration();

0 commit comments

Comments
 (0)