|
4 | 4 |
|
5 | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
6 | 6 | use Symfony\Component\HttpFoundation\RedirectResponse;
|
| 7 | +use Symfony\Component\HttpFoundation\Request; |
7 | 8 | use Acme\DemoBundle\Form\ContactType;
|
8 | 9 |
|
9 | 10 | // these import the "@Route" and "@Template" annotations
|
@@ -34,22 +35,20 @@ public function helloAction($name)
|
34 | 35 | * @Route("/contact", name="_demo_contact")
|
35 | 36 | * @Template()
|
36 | 37 | */
|
37 |
| - public function contactAction() |
| 38 | + public function contactAction(Request $request) |
38 | 39 | {
|
39 |
| - $form = $this->get('form.factory')->create(new ContactType()); |
| 40 | + $form = $this->createForm(new ContactType()); |
| 41 | + $form->handleRequest($request); |
40 | 42 |
|
41 |
| - $request = $this->get('request'); |
42 |
| - if ($request->isMethod('POST')) { |
43 |
| - $form->submit($request); |
44 |
| - if ($form->isValid()) { |
45 |
| - $mailer = $this->get('mailer'); |
46 |
| - // .. setup a message and send it |
47 |
| - // http://symfony.com/doc/current/cookbook/email.html |
| 43 | + if ($form->isValid()) { |
| 44 | + $mailer = $this->get('mailer'); |
| 45 | + |
| 46 | + // .. setup a message and send it |
| 47 | + // http://symfony.com/doc/current/cookbook/email.html |
48 | 48 |
|
49 |
| - $this->get('session')->getFlashBag()->set('notice', 'Message sent!'); |
| 49 | + $request->getSession()->getFlashBag()->set('notice', 'Message sent!'); |
50 | 50 |
|
51 |
| - return new RedirectResponse($this->generateUrl('_demo')); |
52 |
| - } |
| 51 | + return new RedirectResponse($this->generateUrl('_demo')); |
53 | 52 | }
|
54 | 53 |
|
55 | 54 | return array('form' => $form->createView());
|
|
0 commit comments