【发布时间】:2014-01-26 08:45:04
【问题描述】:
在我的 symfony2 项目中,我创建了一个名为“ChoiceAndOrTextType”的新 FormType,它是一个选项列表(复选框),但用户也可以选中“其他" 选项并将他的答案写入 文本字段。
bschussek 的答案中的代码如下所示: Use a conditional statement when creating a form
$builder
->add('choice', 'choice', array(
'choices' => $options['choices'] + array('Other' => 'Other'),
'required' => false,
))
->add('text', 'text', array(
'required' => false,
))
->addModelTransformer(new ValueToChoiceOrTextTransformer($options['choices']))
;
现在我想正确验证这一点,所以当用户检查 “Others” 时,需要填写文本字段,如果未检查“Others”,则它可能是空白。 (一种依赖验证)。
我该怎么做?
【问题讨论】:
标签: php forms validation symfony