I have controller, which render a form which is rendered to every page.
The problem is, that the form doesn't care about submit event.
Every page extends base.html.twig in which is
{{ render(controller('AppBundle:NewsLetter:formRender')) }}
This is the controller:
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Emails;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
class NewsLetterController extends Controller
{
public function formRenderAction(Request $request)
{
$email = new Emails();
$form = $this->createFormBuilder($email)
->add('email', EmailType::class, array('label' => false, 'attr' => array('placeholder' => 'Your e-mail address')))
->add('save', SubmitType::class, array('label' => 'SUBMIT!'))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
die(); //breakpoint
$em = $this->getDoctrine()->getManager();
$em->persist($email);
$em->flush();
$this->addFlash('success', 'Email was successfully saved.');
}
return $this->render('newsLetter.html.twig', array('form' => $form->createView()));
}
}
And finally newsletter.html.twig
<div class="newsletter">
<p>Nechte si zasílat články e-mailem</p>
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
</div>
So the form is correctly rendered, but nothing happens after submit.