views:

26

answers:

1

The default decorator for the Zend_Form_Element_Radio is

<label for="type_id-1"><input type="radio" name="type_id" id="type_id-1" value="1">Pack</label>

The label tag wraps the input tag. Instead I would like to to look like

<input type="radio" name="type_id" id="type_id-1" value="1"><label for="type_id-1">Pack</label>

I thought it might have to do with the "Label" of the element, but that is different. Even with the following code, I still get the label wrapping the radio. When I use this form code.

public function init()
{
    parent::init();

    $this->setName('createdomain');

    $type_id = new Zend_Form_Element_Radio('type_id');
    $type_id->setLabel('Please Choose')
            ->setRequired()
            ->setMultiOptions(array('m' => "male", 'f' => 'female'));

    $this->addElement($type_id);

    $this->setElementDecorators(array(
    'ViewHelper',
     array('Label',array('placement' => 'APPEND')),
));       
}

I get this HTML as a result

<form id="createdomain" enctype="application/x-www-form-urlencoded" action="" method="post"><dl class="zend_form">
<label for="type_id-m"><input type="radio" name="type_id" id="type_id-m" value="m">male</label><br />
<label for="type_id-f"><input type="radio" name="type_id" id="type_id-f" value="f">female</label>
<label for="type_id" class="required">Please Choose</label></dl>
</form>

Notice how there is a label tag wrapping the input tag?

A: 

Try:

$this->setElementDecorators(array(
        'ViewHelper',
         array('Label',array('placement' => 'APPEND')),
    ));

Check out zendcasts video about it its really great. Decorators can be really complicated with ZF but this video really explains it well.

Iznogood
Sorry, that's not it either. With that, Zend just appends another `label` after the two radios. <label for="type_id-1"><input type="radio" value="1" id="type_id-1" name="type_id">Girl</label><br><label for="type_id-2"><input type="radio" value="2" id="type_id-2" name="type_id">Boy</label><label class="required" for="type_id">Make Selection</label>I'm sure the answer lies somewhere in assigning a different ViewHelper to the radio element, but I'm just not sure how to do it. Thank for the help though.
nvoyageur
@nvoyageur you should post more code then because what I posted in my answer works perfectly and does exaclty what you ask for in your question. So something else must be wrong. Post your whole form?
Iznogood
I've updated the question to include the Form code I am using and the result HTML. You'll notice the `input` tag is surrounded by a `label` tag, then both radio buttons are followed by a label for the button set.
nvoyageur
I favorited your question to remember to check it out tonight when I get home from work.
Iznogood