开发者

Zend_Form: Add elements to radio buttons

I'm trying to add Zend_Form_Elemen开发者_C百科ts 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 [___]


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜