Hello I am trying to do a checkbox display like:
<input name="choice2" id="choice2" value="1" type="checkbox">
<label for="choice2" class="optional">Credit Card</label><br />
Some text
<input name="choice2" id="choice2" value="1" type="checkbox">
<label for="choice2" class="optional">Credit Card</label><br />
Some text
I got very close with the following code:
$lbl_spagym = 'Credit Card<br />
<p class="description">Some text</p><br />';
$chk_spagym = new Zend_Form_Element_Checkbox('chk_spagym');
$ch开发者_StackOverflowk_spagym->setLabel($lbl_spagym)
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('Label', array('placement' => 'APPEND', 'escape' => false)),
array('HtmlTag', array('tag' => 'div'))
));
It renders as:
<div>
<input type="hidden" name="chk_bank" value="0" />
<input type="checkbox" name="chk_bank" id="chk_bank" value="1" checked="checked" />
<label for="chk_bank" class="optional">Credit Card<br />
<p class="relocation_descr">Some text</p><br />
</label></div>
But I need the <p></p>
to be out of the label tag because 'some text' is a description and not a label. I played with decorators for days but can not get this behavior right. Would thanks any comments on that.
You should be able to create that markup using something like
$form->addElement('checkbox', 'choice2', array(
'label' => 'Credit Card',
'decorators' => array(
'ViewHelper',
array('Label', array('placement' => 'append',
'class' => 'optional'))
)
));
This will generate a hidden element for the checkbox "off" value but trust me, you want to keep that.
I sorted my problem with:
$checkbox_e->setLabel($e_label)
->setDecorators(array('ViewHelper',
'Description',
'Errors',
array('Label',
array('placement'=>'APPEND')),
array('HtmlTag', array('tag' => 'div'))));
精彩评论