Form- Basic Constraints - Symfony2
uses:
use Symfony\Component\Validator\Constraints\Blank;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Null;
use Symfony\Component\Validator\Constraints\True;
use Symfony\Component\Validator\Constraints\False;
use Symfony\Component\Validator\Constraints\Type;
... class UserType ..
... public function buildForm( ...
$builder->add('name', 'text', array(
'label' => 'Name',
// css
'attr' => array(
'class' => 'someclass',
'id' => 'someID'
),
'constraints' => array(
new Blank(array(
'message' => 'This value should be blank.')
),
new NotBlank(array(
'message' => 'This value should not be blank.')
),
new NotNull(array(
'message' => 'This value should not be null.')
),
new Null(array(
'message' => 'This value should be null.')
),
new True(array(
'message' => 'This value should be true.')
),
new False(array(
'message' => 'This value should be false.')
),
new Type(array(
'message' => 'This value should be of type {{ type }}.',
'type' => 'float ') // * see Type
),
),
)
);
Written by Isaac Limon G.
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#