我有一个Symfony形式的两个相关字段: object_status和cryopreservation_method 。
第一个不能为空并存储三种可能的选择之一: liquid , solid或cryopreserved 。
如果记录的object_status设置为'cryopreserved'则只应设置第二个。 否则为NULL 。
在保存表单之前,如何在服务器端(不使用Javascript)检查这个? 我试图在模型中检查null或空值,但没有运气。
I have two related fields in a Symfony 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.
最满意答案
您必须创建条件验证器。 这可以使用sfValidatorCallback完成(比创建新的验证器更容易)。 查看Symfony Cookbook的这个例子 (适用于1.2但适用于1.4)。
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).
更多推荐
发布评论