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.

Read the rest of this entry »