I am trying to embed a controller in a Twig template like this:
{{ render(controller('IRCGlobalBundle:MailingList:join')) }}
This controller renders a basic form to join a mailing list:
namespace IRC\GlobalBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use IRC\GlobalBundle\Entity\MailingList;
use IRC\GlobalBundle\Form\Type\MailingListType;
class MailingListController extends BaseController
{
public function joinAction(Request $request) {
$this->getSiteFromRequest($request);
$mailingList = new MailingList;
$mailingList->setSite($this->site);
$form = $this->createForm(new MailingListType(), $mailingList);
$form->handleRequest($request);
if ($form->isSubmitted()) {
echo "submitted form";
} else {
echo "unsubmitted form";
}
return $this->render('IRCGlobalBundle:Forms:join_mailing_list.html.twig', array(
'form' => $form->createView(),
));
}
}
The problem is that the $form->isSubmitted() method never returns true so the form submission cannot be validated/handled. What am I doing wrong? Do I need to change the target of the form to point to my embedded controller?