@@ -9,31 +9,102 @@ URL under which the form was rendered. Sometimes you want to change these
99parameters. You can do so in a few different ways.
1010
1111If you use the :class: `Symfony\\ Component\\ Form\\ FormBuilder ` to build your
12- form, you can use ``setAction() `` and ``setMethod() ``::
12+ form, you can use ``setAction() `` and ``setMethod() ``:
1313
14- $form = $this->createFormBuilder($task)
15- ->setAction($this->generateUrl('target_route'))
16- ->setMethod('GET')
17- ->add('task', 'text')
18- ->add('dueDate', 'date')
19- ->add('save', 'submit')
20- ->getForm();
14+ .. configuration-block ::
15+
16+ .. code-block :: php-symfony
17+
18+ // AppBundle/Controller/DefaultController.php
19+ namespace AppBundle\Controller;
20+
21+ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
22+
23+ class DefaultController extends Controller
24+ {
25+ public function newAction()
26+ {
27+ $form = $this->createFormBuilder($task)
28+ ->setAction($this->generateUrl('target_route'))
29+ ->setMethod('GET')
30+ ->add('task', 'text')
31+ ->add('dueDate', 'date')
32+ ->add('save', 'submit')
33+ ->getForm();
34+
35+ // ...
36+ }
37+ }
38+
39+ .. code-block :: php-standalone
40+
41+ use Symfony\Component\Form\Forms;
42+
43+ // ...
44+
45+ $formFactoryBuilder = Forms::createFormFactoryBuilder();
46+
47+ // Form factory builder configuration ...
48+
49+ $formFactory = $formFactoryBuilder->getFormFactory();
50+
51+ $form = $formFactory->createBuilder('form', $task)
52+ ->setAction($this->generateUrl('target_route'))
53+ ->setMethod('GET')
54+ ->add('task', 'text')
55+ ->add('dueDate', 'date')
56+ ->add('save', 'submit')
57+ ->getForm();
2158
2259 .. note ::
2360
2461 This example assumes that you've created a route called ``target_route ``
2562 that points to the controller that processes the form.
2663
2764When using a form type class, you can pass the action and method as form
28- options::
65+ options:
2966
30- use AppBundle\Form\TaskType;
31- // ...
67+ .. configuration-block ::
68+
69+ .. code-block :: php-symfony
70+
71+ // AppBundle/Controller/DefaultController.php
72+ namespace AppBundle\Controller;
73+
74+ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
75+ use AppBundle\Form\TaskType;
76+
77+ class DefaultController extends Controller
78+ {
79+ public function newAction()
80+ {
81+ // ...
82+
83+ $form = $this->createForm(new TaskType(), $task, array(
84+ 'action' => $this->generateUrl('target_route'),
85+ 'method' => 'GET',
86+ ));
87+
88+ // ...
89+ }
90+ }
91+
3292
33- $form = $this->createForm(new TaskType(), $task, array(
34- 'action' => $this->generateUrl('target_route'),
35- 'method' => 'GET',
36- ));
93+ .. code-block :: php-standalone
94+
95+ use Symfony\Component\Form\Forms;
96+ use AppBundle\Form\TaskType;
97+
98+ $formFactoryBuilder = Forms::createFormFactoryBuilder();
99+
100+ // Form factory builder configuration ...
101+
102+ $formFactory = $formFactoryBuilder->getFormFactory();
103+
104+ $form = $formFactory->create(new TaskType(), $task, array(
105+ 'action' => $this->generateUrl('target_route'),
106+ 'method' => 'GET',
107+ ));
37108
38109 Finally, you can override the action and method in the template by passing them
39110to the ``form() `` or the ``form_start() `` helper functions:
0 commit comments