Skip to content

Instantly share code, notes, and snippets.

@szatan szatan/gist:5291506
Created Apr 2, 2013

What would you like to do?
namespace Acme\DemoBundle\Form\Type;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Validator\Constraints\Type;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Email;
class SettingsFormType extends AbstractType
private $settings;
public function __construct(\Acme\DemoBundle\Helper\SettingsManager $settings)
$this->settings = $settings;
public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add('sampleEmailSetting', 'text', array(
'label' => 'Sample email',
'data' => $this->settings->get('sampleEmailSetting'),
'constraints' => new Email()
$builder->add('sampleNumberSetting', 'text', array(
'label' => 'Sample number',
'data' => $this->settings->get('sampleNumberSetting'),
'constraints' => new Regex(array('pattern' => "/^\d+$/", 'message' => 'This value needs to be numeric'))
public function getName()
return 'settings_form';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.