Skip to content

Instantly share code, notes, and snippets.

@PhazeonPhoenix
Created April 17, 2012 19:29
  • Select an option

Select an option

Revisions

  1. PhazeonPhoenix created this gist Apr 17, 2012.
    30 changes: 30 additions & 0 deletions gistfile1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php
    namespace Acme\DemoBundle\Form\Type;

    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilder;

    use Symfony\Component\Validator\Constraints as Assert;

    class DemoType extends AbstractType
    {
    public function buildForm(FormBuilder $builder, array $options)
    {
    $builder->add('name');
    $builder->add('email', 'email', array('label' => 'Your Email'));
    }

    public function getName()
    {
    return 'demo';
    }
    public function getDefaultOptions(array $options)
    {
    $collectionConstraint = new Assert/Collection(array(
    'name' => new Assert/MinLength(5),
    'email' => new Assert/Email(array('message' => 'Invalid email address')),
    ));

    return array('validation_constraint' => $collectionConstraint);
    }
    }