0

The case seemed fairly simple, there is a DTO object containing

class ConfirmationMessageDto
{
    /**
     * @var mixed
     *
     * @Assert\NotNull
     * @Assert\Type(type = "bool")
     */
     protected $success;

    /**
     * @var mixed
     *
     * @Assert\Type(type = "string")
     */
     protected $errorMessage;

     [setters and getters]
}

Now I'd like it to validate if the errorMessage is not null when $success === false. Can I do it in a simple way?

Kalmar
  • 739
  • 2
  • 11
  • 23
  • 3
    Possible duplicate of [Symfony2 form validation based on two fields](https://stackoverflow.com/questions/8170301/symfony2-form-validation-based-on-two-fields), [How to validate a property dependent on another property in Symfony 2](https://stackoverflow.com/questions/12260705/how-to-validate-a-property-dependent-on-another-property-in-symfony-2) and [Conditional validation of fields based on other field value in Symfony2](https://stackoverflow.com/questions/30206854/conditional-validation-of-fields-based-on-other-field-value-in-symfony2) – Jenne Jun 06 '17 at 07:15
  • 3
    a custom validator or more simply a callbackValidator – Matteo Jun 06 '17 at 07:51
  • Another way would be [Expression Constraint](http://symfony.com/doc/current/reference/constraints/Expression.html) – V-Light Jun 06 '17 at 10:02
  • Dynamic validation groups which can be defined in the Form. I did something similar on a page where a user can change either password or email or both on a single submit button. – Marko Živković Jun 06 '17 at 10:46

0 Answers0