I want to validate form using asserts in Entity class but when I submit the form, it says $form->isValid() is true.
Here is how I got it setup:
// config.yml
validation: { enabled: true, enable_annotations: false }
// validation.yml
Software\Bundle\Entity\Program:
properties:
name:
- NotBlank: ~
// MyForm
...
$builder
->add('name', 'text', [
'label' => 'word.name'
])
;
...
// Program.php
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
I tried also via Annotations but it did not help. I know I can put 'constraints' property to my form and there set new NotBlank() but I want to have that validation on Entity level since I am going to use an API and I want to have validation in one place instead of two.
Is my validation.yml file ignored or what?
EDIT I did not mention one important thing that my form is embedded into another one. in this case you must use 'cascade_validation' property in your form options.
This answer helped me a lot Symfony2 - Validation not working for embedded Form Type