From 85def33e2a704ff1d5f8d705c5ceb6ba8f562a71 Mon Sep 17 00:00:00 2001 From: Xavier Briand Date: Mon, 22 Nov 2010 10:02:48 +0100 Subject: [PATCH 1/6] [Forms/overview] removed templating.form call for template form arguments --- guides/forms/overview.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/forms/overview.rst b/guides/forms/overview.rst index 4e5aa384a4e..7514fa1cb1b 100644 --- a/guides/forms/overview.rst +++ b/guides/forms/overview.rst @@ -49,7 +49,7 @@ Now let's create a form to let the visitor fill the data of the object:: $form->add(new IntegerField('age')); return $this->render('HelloBundle:Hello:signup.php', array( - 'form' => $this->get('templating.form')->get($form) + 'form' => $form )); } From d7aa603a6b3aefc57a23d3d5ac68dad64c95fbbc Mon Sep 17 00:00:00 2001 From: Xavier Briand Date: Mon, 22 Nov 2010 10:04:02 +0100 Subject: [PATCH 2/6] [Forms/overview] added namespace details --- guides/forms/overview.rst | 8 ++++++++ 1 file changed, 8 insertions(+) mode change 100644 => 100755 guides/forms/overview.rst diff --git a/guides/forms/overview.rst b/guides/forms/overview.rst old mode 100644 new mode 100755 index 7514fa1cb1b..33efeaa701c --- a/guides/forms/overview.rst +++ b/guides/forms/overview.rst @@ -18,6 +18,8 @@ the object. Let's see how this works in a practical example. Let's create a simple ``Customer`` class:: + namespace Application\HelloBundle\Entity; + class Customer { public $name; @@ -40,6 +42,12 @@ is public, while ``$age`` can only be modified through setters and getters. Now let's create a form to let the visitor fill the data of the object:: // src/Application/HelloBundle/Controller/HelloController.php + + use Application\HelloBundle\Entity\Customer; + use Symfony\Component\Form\Form; + use Symfony\Component\Form\TextField; + use Symfony\Component\Form\IntegerField; + public function signupAction() { $customer = new Customer(); From 7c881e3a5ef914ffd049ffb8e4126ce067587834 Mon Sep 17 00:00:00 2001 From: Xavier Briand Date: Mon, 22 Nov 2010 11:07:04 +0100 Subject: [PATCH 3/6] [Forms/overview] updated form rendering in template --- guides/forms/overview.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/guides/forms/overview.rst b/guides/forms/overview.rst index 33efeaa701c..52db3576848 100755 --- a/guides/forms/overview.rst +++ b/guides/forms/overview.rst @@ -76,17 +76,15 @@ Let's create a simple template to render the form: # src/Application/HelloBundle/Resources/views/Hello/signup.php extend('HelloBundle::layout.php') ?> - form('#') ?> - render() ?> +
enctype($form) ?> method="post"> + render($form) ?>
.. note:: - Form rendering in templates is covered in two dedicated chapters: one for - :doc:`PHP templates `, and one for :doc:`Twig templates - `. + Form rendering in templates is covered in chapter :doc:`PHP templates `. When the user submits the form, we also need to handle the submitted data. All the data is stored in a POST parameter with the name of the form:: From 1df6b2c1c6ca80543a5a67ae84464ebf4ac98e6c Mon Sep 17 00:00:00 2001 From: Xavier Briand Date: Mon, 22 Nov 2010 11:23:32 +0100 Subject: [PATCH 4/6] [Forms/overview] added namespace --- guides/forms/overview.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/guides/forms/overview.rst b/guides/forms/overview.rst index 52db3576848..8c65d59ace1 100755 --- a/guides/forms/overview.rst +++ b/guides/forms/overview.rst @@ -188,6 +188,9 @@ We can use a field group to show fields for the customer and the nested address at the same time:: # src/Application/HelloBundle/Controller/HelloController.php + + use Symfony\Component\Form\FieldGroup; + public function signupAction() { $customer = new Customer(); @@ -213,6 +216,8 @@ The ``RepeatedField`` is an extended field group that allows you to output a field twice. The repeated field will only validate if the user enters the same value in both fields:: + use Symfony\Component\Form\RepeatedField; + $form->add(new RepeatedField(new TextField('email'))); This is a very useful field for querying email addresses or passwords! @@ -233,6 +238,8 @@ will extend the ``Customer`` class to store three email addresses:: We will now add a ``CollectionField`` to manipulate these addresses:: + use Symfony\Component\Form\CollectionField; + $form->add(new CollectionField(new TextField('emails'))); If you set the option "modifiable" to ``true``, you can even add or remove From baf7b2dcd35dc3e064b3834593a5658ef3151736 Mon Sep 17 00:00:00 2001 From: Xavier Briand Date: Mon, 22 Nov 2010 11:29:41 +0100 Subject: [PATCH 5/6] [Forms/overview] added namespace --- guides/forms/overview.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guides/forms/overview.rst b/guides/forms/overview.rst index 8c65d59ace1..0b20c409248 100755 --- a/guides/forms/overview.rst +++ b/guides/forms/overview.rst @@ -267,6 +267,8 @@ accepting terms and conditions. Let's create a simple ``Registration`` class for this purpose:: + namespace Application\HelloBundle\Entity; + class Registration { /** @validation:Valid */ @@ -284,6 +286,10 @@ Let's create a simple ``Registration`` class for this purpose:: Now we can easily adapt the form in the controller:: # src/Application/HelloBundle/Controller/HelloController.php + + use Application\HelloBundle\Entity\Registration; + use Symfony\Component\Form\CheckboxField; + public function signupAction() { $registration = new Registration(); From c8fdd9a3164d27c5952c87a75d7b9daf9eedf74f Mon Sep 17 00:00:00 2001 From: Xavier Briand Date: Mon, 22 Nov 2010 11:35:44 +0100 Subject: [PATCH 6/6] [Forms/overview] removed enctype from template --- guides/forms/overview.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/forms/overview.rst b/guides/forms/overview.rst index 0b20c409248..2fb8b3acdcd 100755 --- a/guides/forms/overview.rst +++ b/guides/forms/overview.rst @@ -76,7 +76,7 @@ Let's create a simple template to render the form: # src/Application/HelloBundle/Resources/views/Hello/signup.php extend('HelloBundle::layout.php') ?> -
enctype($form) ?> method="post"> + render($form) ?>