Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting some HTML next to a radio button in Zend Form

I have built a form builder, and I need the ability to assign description to every option in a radio element. Upon creation of this radio element, I ask the user to assign each value a description, which should be shown next to the element. So, in my database, I have a value, a title and a description for each option in this radio element.

The question: How do I put something next to a radio element? Do I have to create a new way for the form to render radio elements, or can it be done via decorators?

Any little bit helps, useful reading is welcome too!

A representation of what i need:

**A title of the Radio element**
      O Option 1       -    A description for option 1    
      O Option 2       -    A description for option 2    
      O Option 3       -    A description for option 3    
      O Option 4       -    A description for option 4    

Any ideas?

like image 653
Janis Peisenieks Avatar asked Dec 13 '10 19:12

Janis Peisenieks


1 Answers

It's hard to tell from your question but where abouts is the actual radio button in your markup?

If it's to the left or right of the option label, you can simply use the label to enter your extra markup and set the ViewHelper's escape property to false to enable HTML


For example

$form->addElement('radio', 'test', array(
    'label' => '**A title of the Radio element**',
    'multiOptions' => array(
        1 => 'Option 1 <strong>- A description for option 1</strong>',
        2 => 'Option 2 <strong>- A description for option 2</strong>'
    ),
    'escape' => false
));

Looks like this

Form Screenshot

like image 88
Phil Avatar answered Nov 15 '22 11:11

Phil