I need to implement form validation depending on submitted data. While data object’s invoice property is true then validation_groups array should contain not only ‘add’ validation but also ‘company’.
I’ve found “Groups based on Submitted Data” chapter in Symfony Docs https://github.com/symfony/symfony-docs/blob/master/book/forms.rst.
The problem is that :
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Strict\PublicBundle\Entity\Booking',
'validation_groups' => function(FormInterface $form)
{
return array('booking');
},
);
}
throws this error:
Warning: Illegal offset type in /var/www/vendor/symfony/src/Symfony/Component/Validator/GraphWalker.php line 101
500 Internal Server Error – ErrorException
Any ideas what can be wrong?
According to this pull request using callbacks for
validation_groupswill be posible in Symfony 2.1 (not yet released, currentlymasterbranch).Are you sure you are using master branch? If you are using current stable (2.0.x), it has no support for Groups based on Submitted Data, you have to use arrays only. See proper documentation on http://symfony.com/doc/current/book/forms.html#book-forms-validation-groups.