Created
April 17, 2012 19:29
-
-
Save PhazeonPhoenix/2408452 to your computer and use it in GitHub Desktop.
Symfony: Objectless Form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment