In Symfony2, if you’re using AbstractType to generate web forms, you may need to generate errors specific to one of the form’s input elements. Below is an example app with a warning message added to the session FlashBag if a resource doesn’t exist when the checkbox is ticked. The focus will be on MyController.php line 24 and its call to $form->get('yourCheckbox')->getConfig()->getOption('label') so you don’t have to hard-code the label in a controller action method.

This source code assumes you’re using Doctrine as an ORM and the Twig templating language. I’ve omitting Symfony2 routing, bundle, and app configurations.





When visiting the above action method and _isResourceUploaded() returns false, the view will display:

Warning “Check to enable resource” is ticked but has no resources assigned. Please re-upload.