I create and render my form using form builder but it seems that validation is disabled or work not properly. I keep my validation rules in validation.yml file. Method $form->isValid()
always return true
, and $form->getErrorsAsString()
doesn't show any errors (only [FieldName1]: No errors, [FieldName2]: No errors ... etc
).
I create form in this way:
$form = $this->createForm( new CategoryType(), new Category() );
Then I send it to a twig.
What could be the reason? How do I enable validation?
----- UPDATE -------------------------
I create a form in this way:
public function indexAction()
{
return $this->render('MyBundle:MyView:index.html.twig', array(
"form" => $this->createForm( new CategoryType(), new Category() )->createView()
));
}
CategoryType is very simple:
class CategoryType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder ->add('name', 'text')
->add('categoryId', 'entity', array(
'class' => 'MyBundle:Category',
'property' => 'name',
));
}
public function getName() {
return 'my_form_name';
}
}
And of course validation.yml:
MyBundle/Form/Type/CategoryType:
properties:
- name:
- NotBlank: ~
- Length:
min: 3
max: 30
MyBundle/Entity/Category:
properties:
- name:
- NotBlank: ~
- Length:
min: 3
max: 30
I do not know exactly which version should I use, but both of them doesn't work.