Question

I have a custom validator in Symfony2 and I would like to get one of the submited values from my form.

When vardumping the $value from

public function validate($value, Constraint $constraint)

I can see the variable I need, but the result is too big in order to be able to find where is my request parameter placed.

Thank you in advance.

Was it helpful?

Solution

I have found a workaround to this problem:

  1. I created a new field in my entity that does not exists in the database, but exists in the form.

  2. In the validator class, I am accessing all the entity values, and also this new one that I need.

FYI, in order to access all the entity object in the validator, you need to put:

public function getTargets()
{
    return self::CLASS_CONSTRAINT;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top