I want to make a newsletter in a footer with my service. To do that, I have to embed a controller in a view :
{{ render(controller('AppBundle:RegisterNewsletter:registerToTheNewsletter')) }}
The probleme is that when I submit my form, the page is refreshed but nothing else, even I insert a "die;"
public function registerToTheNewsletterAction(Request $request)
{
$form = $this->createFormBuilder()
->add('email', EmailType::class)
->add('subscribe', SubmitType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
var_dump($data);
die;
}
return $this->render('include/registerNewsletter.html.twig', array('form' => $form->createView()));
}
Thanks for your help
I've got a solution, when I said, I had to embed a controller in a view. In fact during the submitting, the page is refreshed and the data is lost.
So I change the action of the form to redirect the data on an other path, the data is processed in an other action and I redirect on the referer.
If you want more explains, ask me