I am doing a form with Symfony 2.3 to suscribe to a newsletter. The form is working good in is own template (newsletter.html.twig).
My controller action:
public function newsletterAction(Request $request)
{
$newsletter = new Newsletter();
$form = $this->createFormBuilder($newsletter)
->add('email', 'email')
->add('submit', 'submit')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($newsletter);
$em->flush();
$request->getSession()->getFlashBag()->add('notice', 'Vous venez de vous enregistré à la Newsletter d\'Emoovio.');
}
return $this->render('MyBundle:Global:newsletter.html.twig', array(
'form' => $form->createView(),
));
}
My template where it's working (newsletter.html.twig) :
{{ form(form) }}
My template where it does not work (index.html.twig):
////
{% render (controller("EmooviofrontBundle:Global:newsletter")) %}
////
The form is display but it's not working. May be is miss something. Has anyone had the same problem and could explain me. Thank you.