I have assert configured in my entity. I created two forms types. In the first, I have name
and url
. In the second I have description
.
/*
*@Assert/NotBlank()
*/
$description;
When I try to submit the first form, it is not validated because the $description
is blank.
But in the first form, not have the description field.
What you are looking for are validation groups (http://symfony.com/doc/current/book/validation.html#validation-groups and http://symfony.com/doc/current/book/forms.html#validation-groups).
Basically for your case you need to define two validation groups and set each one of them on your form types.
YourEntity
/**
* @Assert\NotBlank(groups={"FirstForm"})
*/
private $name;
/**
* @Assert\NotBlank(groups={"FirstForm"})
*/
private $url;
/**
* @Assert\NotBlank(groups={"SecondForm"})
*/
private $description;
FirstFormType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'validation_groups' => ['Default', 'FirstForm']
));
}
SecondFormType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'validation_groups' => ['Default', 'SecondForm']
));
}