Zend_Form:向单选按钮添加元素

发布于 2024-09-12 13:03:08 字数 162 浏览 5 评论 0原文

我正在尝试在表单中的单选按钮后面添加 Zend_Form_Elements,但到目前为止我还无法这样做。如果有人能指出我正确的方向,我将不胜感激。表单需要渲染如下图:

(*) [____]%

( ) [____]€

( ) [___] for [___]

I'm trying to add Zend_Form_Elements following the radio buttons in my form, but so far I have been unable to do so. If anyone could point me in the right direction it would be greatly appreciated. Form needs to be rendered as shown below:

(*) [____]%

( ) [____]€

( ) [___] for [___]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

白云悠悠 2024-09-19 13:03:08

像这样的事情怎么样:

class My_RadioForm extends Zend_Form
{
    public function init()
    {
        $this->addElement('radio', 'myradio', array(
            'label' => 'Select an option below',
            'multiOptions' => array(
                'val1'  => 'Text 1',
                'val2'  => 'Text 2',
                'val3'  => 'Text 2',
            ),
        ));
    }

}

对于非常具体的渲染,@iznogood 是对的:必须进入所有装饰器业务。

How about something like this:

class My_RadioForm extends Zend_Form
{
    public function init()
    {
        $this->addElement('radio', 'myradio', array(
            'label' => 'Select an option below',
            'multiOptions' => array(
                'val1'  => 'Text 1',
                'val2'  => 'Text 2',
                'val3'  => 'Text 2',
            ),
        ));
    }

}

For very specific rendering, @iznogood is right: gotta get into all that the decorator business.

北陌 2024-09-19 13:03:08

使用表单 装饰器 和 css 根据需要设置输入样式。

您可以使用表单装饰器来重写表单的标记。但坦率地说,这是一个相当大的挑战,也许你最好的选择是表单 viewScript。实现起来非常容易,并且可以让您对表单的 html 进行 100% 的控制。查看

示例:使用 ViewScript 装饰器进行完全自定义

在我链接的示例中。

Use form decorators and css to style the input as you want.

You woulduse a forn decorator to rewrite the markup for your form. But its quite a challenge franckly and maybe your best bet is a form viewScript. There very easy to implement and give you 100% control over the html for the form. Look at

Example: Full Customization Using the ViewScript Decorator

In the example I linked.

凝望流年 2024-09-19 13:03:08

如果只是定位输入标签的问题,您可以使用 docorators。您可以通过覆盖/修改默认的 FormElements 装饰器来做到这一点,例如,通过向特定表单元素添加 float: left 样式属性。继续 David 的示例:

 $this->addElement('radio', 'myradio', array(
        'label' => 'Select an option below',
        'multiOptions' => array(
            'val1'  => 'Text 1',
            'val2'  => 'Text 2',
            'val3'  => 'Text 2',
        ), 
        'decorators' =>
          array(
          'ViewHelper',
          'Errors',
          'Description',
          array('HtmlTag', array('tag' => 'dd', 'style' => 'float: left')),
          'Label'
        )
));

还有一个 setDefaultDecorators() 方法,它允许您覆盖整个表单中的所有元素装饰器。

如果要创建复合元素,则更高级的解决方案 - http://weierophinney.net /matthew/archives/217-Creating-composite-elements.html - 即包含多个输入标签的自定义表单元素。这样您就可以更好地控制表单业务逻辑。

You could use docorators if it is only a matter of positioning input tags. You can do that by overwriting/modifying default FormElements decorator, for example, by adding float: left style property to particular form element. Continuing from David's example:

 $this->addElement('radio', 'myradio', array(
        'label' => 'Select an option below',
        'multiOptions' => array(
            'val1'  => 'Text 1',
            'val2'  => 'Text 2',
            'val3'  => 'Text 2',
        ), 
        'decorators' =>
          array(
          'ViewHelper',
          'Errors',
          'Description',
          array('HtmlTag', array('tag' => 'dd', 'style' => 'float: left')),
          'Label'
        )
));

There is also a setDefaultDecorators() method, that allows you to overwrite all elements decorators in entire form.

More advanced solution if to create composite elements - http://weierophinney.net/matthew/archives/217-Creating-composite-elements.html - i.e. custom form element containing multiple input tags. You have more control over your form business logic that way.

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