表格Symfony 2.3订阅

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.

I think that when you submit your form, the POST data arrives in the indexAction. This action does not validate your form and renders the normal page. While rendering it will call the Global:newsletterAction but just as a sub request in the GET method without form data.

You could try to apply an action to your formdata

    $form = $this->createFormBuilder($newsletter, array(
        'action' => $this->generateUrl('global_newsletter'),
        'method' => 'POST',
    ))
   ->add('email', 'email')
   ->add('submit', 'submit')
   ->getForm();