开发者

Validate a field depending on another field value in Symfony

I have two related fields in a Sym开发者_Go百科fony form: object_status and cryopreservation_method.

The first one cannot be null and stores one of three possible choices: liquid, solid or cryopreserved.

The second one should be only set if a record has its object_status set to 'cryopreserved'. Otherwise it is NULL.

How can I check this in the server side (not with Javascript) before saving the form? I have tried to check for null or empty values in model, but with no luck.


You have to create a conditional validator. This can be done using a sfValidatorCallback (easier than creating a new validator). Check this example of the Symfony Cookbook (is for 1.2 but works in 1.4).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜