Janis Peisenieks
Janis Peisenieks

Reputation: 4998

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?

Upvotes: 5

Views: 3845

Answers (2)

Phil
Phil

Reputation: 164809

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

Upvotes: 12

Wes
Wes

Reputation: 408

Check out the tutorial I wrote solving this problem.

http://wesleyalmeida.net/what-ive-learned/how-to-decorate-a-radio-element-in-zend/

Upvotes: 0

Related Questions