Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Commit 102eb00

Browse files
dostenfabpot
authored andcommitted
Refactored contact action to use new form methods in 2.3
1 parent 8fe6950 commit 102eb00

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/Acme/DemoBundle/Controller/DemoController.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
66
use Symfony\Component\HttpFoundation\RedirectResponse;
7+
use Symfony\Component\HttpFoundation\Request;
78
use Acme\DemoBundle\Form\ContactType;
89

910
// these import the "@Route" and "@Template" annotations
@@ -34,22 +35,20 @@ public function helloAction($name)
3435
* @Route("/contact", name="_demo_contact")
3536
* @Template()
3637
*/
37-
public function contactAction()
38+
public function contactAction(Request $request)
3839
{
39-
$form = $this->get('form.factory')->create(new ContactType());
40+
$form = $this->createForm(new ContactType());
41+
$form->handleRequest($request);
4042

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
4848

49-
$this->get('session')->getFlashBag()->set('notice', 'Message sent!');
49+
$request->getSession()->getFlashBag()->set('notice', 'Message sent!');
5050

51-
return new RedirectResponse($this->generateUrl('_demo'));
52-
}
51+
return new RedirectResponse($this->generateUrl('_demo'));
5352
}
5453

5554
return array('form' => $form->createView());

0 commit comments

Comments
 (0)