I recently cleaned my Twig templates in order to avoid deprecated calls on Symfony 2.8 and I got a strange behaviour.
This is how my template looks like :
{{ form_start(form, {'attr': {'class': 'form_template'} }) }}
{{ form_widget(form) }}
<input type="submit" value="Send"/>
{{ form_end(form) }}
This is how my form looks like :
class MyFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('email', 'text', array('label' => 'your email'));
}
public function getName()
{
return 'some_fancy_name';
}
}
And this is how my controller looks like
public function someAction(Request $request)
{
$form = $this->createForm(new MyFormType(), null);
if ($request->getMethod() == 'POST')
{
// do something with the form contents
return $this->redirect($this->generateUrl('somewhere'));
}
return $this->render('::myform.html.twig', array(
'form' => $form->createView(),
));
}
When rendering the template, everything is working fine until Twig renders the form_end()
function and then throws an Error: Maximum function nesting level of '100' reached, aborting! (500 Internal Server Error)
I tried increasing the xdebug.max_nesting_level
setting in my PHP configuration but it did not help, the only fix that I found which resolves the issue is :
{{ form_start(form, {'attr': {'class': 'form_template'} }) }}
{{ form_widget(form) }}
<input type="submit" value="Send"/>
{{ form_rest(form) }}
</form>
Which is an ugly fix.
Now I am wondering why am I getting such error with form_end(form)
while everything works fine with form_rest(form)
?