下面是在Zend_Form中创建带有Yes / No选项的单选按钮元素的示例代码.关于如何将所需答案设置为是的任何想法,所以如果选择否,它将无法验证?以下代码将接受是或否.
$question= new Zend_Form_Element_Radio('question'); $question->setrequired(true) ->setLabel('Are you sure?') ->setMultiOptions(array('Yes','No'));
不确定这是否是最佳方式,但它对我有用:
$questionValid = new Zend_Validate_InArray(array('Yes')); $questionValid->setMessage('Yes is required!'); $question = new Zend_Form_Element_Radio('question'); $question->setrequired(true) ->setLabel('Are you sure?') ->setMultiOptions(array('Yes'=>'Yes','No'=>'No')) ->addValidator($questionValid);