visit our site

Symfony2: How to Check If a Form Field Has Errors in Twig

In PHP and Symfony

by Dragos Holban on January 7, 2015

Sometimes you need to check if a field or even the entire form has errors before rendering them (e.g. when adding an errors container). Here’s the code snippet that allows you to check for the errors form variable:

 

One Reply to “Symfony2: How to Check If a Form Field Has Errors in Twig”

  1. Bonjour Amelieil va te falloir silmeepmnt ajouter la ligne suivante required => false,// Rend le champ facultatifdans ta description du champ au niveau du formulaireainsi tu pourra avoir $builder->add(‘nomsite’, ‘entity’, array( ‘label’ => ‘Service:’, ‘class’ => ‘CnceAnnuaireBundle:Site’, ‘property’ => ‘nomsite’, ‘required’ => false,// Rend le champ facultatif ’empty_value’ => ‘Dans tous les services’, ));

Leave a Reply

Your email address will not be published. Required fields are marked *

+1
Share
Tweet
Share
Stumble
Pin