Symfony2 form validation based on two fields

前端 未结 5 2056
醉梦人生
醉梦人生 2020-12-05 05:04

I am currently developing a Website in which user may buy gift cards. I am using a three step form using the CraueFormFlow bundle and everything is concerning the steps. I a

5条回答
  •  渐次进展
    2020-12-05 05:53

    I'd suggest using Expression constraint. This constraint can be applied on form field or (preferably) in entity:

       /**
         * @var int
         * @Assert\Type(type="integer")
         */
        private $amountGiftCards25;
    
        /**
         * @var int
         * @Assert\Type(type="integer")
         * @Assert\Expression(expression="this.getAmountGiftCards25() > 0 or value > 0", message="Please choose amount of gift cards.")
         */
        private $amountGiftCards50;
    

提交回复
热议问题