I need to render a controller in a template (principal.html.twig) with @Route and @Template annotations in order to create a form:
{{ render(controller('PprsBundle:Default:SupuestoConfig'), {'strategy': 'inline'}) }
Controller:
/**
* @Route("/configsup", name="configsup")
* @Template("PprsBundle:Default:SupuestoConfig.html.twig")
*/
public function SupuestoConfigAction()
{
...
->add('number', 'text', array(
'constraints' => new Length(array(
'min' => 1,
'max' => 2,
)),
....
}
routing.yml:
configsup:
resource: "@PprsBundle/Controller"
type: annotation
SupuestoConfig.html.twig:
<form id="configurador" action="{{ path('configsup') }}" method="POST">
<p class="titulo_configurador">Elija supuesto penal:</p>
{{ form_row(form.tipo) }}
{{ form_row(form.numero, { 'label' : ' ', 'attr' : { 'class' : 'rec3' }}) }}
{{ form_rest(form) }}
<input id= "btTipoSupuesto" type="submit" value="Cargar" class="inputbt"/>
</form>
I'm having an unexpected behaviour when the constraint is activated (when I introduce a 4 digits number in "number" field) because it only renders the view SupuestoConfig.html.twig showing the constraint error (route /configsup) instead of the whole page (principal.html.twig). How can i make it work?
SupuestoConfigActionyou can forward the action to the "principal" action if the form is invalid so it renders the whole page not only the form. - Michal Trojanowski