如何使用 Zend Framework 将单选按钮添加到表单?
问题不在于添加单选按钮表单元素,而在于如何在我的脚本格式中匹配它。看起来 zend 中有多种做事的方法。
这是我的脚本:
$this->addElement('text', 'time_from', array(
'id' => 'datepicker',
'class' => 'time_from',
'filters' => array('StringTrim', 'StripTags'),
'required' => true,
'label' => 'Start Date of the Week: ',
'value' => ''
));
$update = $this->addElement('submit', 'update', array(
'required' => false,
'ignore' => true,
'label' => 'Change Time'
));
基于此模板,如何添加单选按钮?
我相信一个合乎逻辑的方法是使用这样的东西:
$this->addElement('radio', 'test', array(
'label'=>'Test Thing',
'addMultiOptions'=>array(
'male' => 'Male',
'female' => 'Female'
),
));
但这不显示任何单选按钮。
我还尝试将 : 替换
'male' => 'Male',
'female' => 'Female'
为 和 数组,但出现了各种错误:
array('male'=>'Male', 'female'=>'Female')
关于如何执行此操作的任何想法?
而且,如果问得也不过分,也许有人可以解释为什么有这么多方法来实现这种形式,以及它们之间的共同点是什么。
谢谢
the issue is not so much as adding a radio button form element but how to i match it in my script format. It looks like there are multiple ways of doing things in zend.
here is my script:
$this->addElement('text', 'time_from', array(
'id' => 'datepicker',
'class' => 'time_from',
'filters' => array('StringTrim', 'StripTags'),
'required' => true,
'label' => 'Start Date of the Week: ',
'value' => ''
));
$update = $this->addElement('submit', 'update', array(
'required' => false,
'ignore' => true,
'label' => 'Change Time'
));
based on this template, how do i add a radio button?
i believe a logical approach would be to use something like this:
$this->addElement('radio', 'test', array(
'label'=>'Test Thing',
'addMultiOptions'=>array(
'male' => 'Male',
'female' => 'Female'
),
));
but this doesn't display any radio buttons.
I've also tried to replace the :
'male' => 'Male',
'female' => 'Female'
with and array, but i get all kind of errors:
array('male'=>'Male', 'female'=>'Female')
any ideas on how to do this?
and , if is ot too much to ask maybe someone can explain why so many ways to do this forms and what is the common nominator in between them.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您说得很对,但是由于您使用
addElement()
构造元素,因此没有addMultiOptions
(函数名称),它只是multiOptions
>。您可以在此处查看所有 Zend_Form 元素的摘要 编辑: 更新了链接。
You were quite right, but since you construct the element with
addElement()
you don't haveaddMultiOptions
(the function name), it's justmultiOptions
.You can see a summary of all Zend_Form elements here Edit: updated link.