如何使用 Zend Framework 将单选按钮添加到表单?

发布于 2024-12-17 12:23:36 字数 1172 浏览 3 评论 0原文

问题不在于添加单选按钮表单元素,而在于如何在我的脚本格式中匹配它。看起来 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悍妇囚夫 2024-12-24 12:23:36

您说得很对,但是由于您使用 addElement() 构造元素,因此没有 addMultiOptions (函数名称),它只是 multiOptions >。

$this->addElement('radio', 'test', array(
    'label'=>'Test Thing',
    'multiOptions'=>array(
        'male' => 'Male',
        'female' => 'Female',
    ),
));

您可以在此处查看所有 Zend_Form 元素的摘要 编辑: 更新了链接。

You were quite right, but since you construct the element with addElement() you don't have addMultiOptions (the function name), it's just multiOptions.

$this->addElement('radio', 'test', array(
    'label'=>'Test Thing',
    'multiOptions'=>array(
        'male' => 'Male',
        'female' => 'Female',
    ),
));

You can see a summary of all Zend_Form elements here Edit: updated link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文