我有一个 zend 表单,我需要 Radio Group 的最终输出 HTML 是这样的:
<div>
<span class='radio_title'>Gender</span> <!-- The issue is in this line -->
<span class='felement'>
<label ....> <input type="radio" ...... value="male" /></label>
<label ....> <input type="radio" ...... value="female" /></label>
</span>
</div>
(ie) 用自定义的 div 或 span 标签替换默认的 dt 和 dd
我创建了一个装饰器,如下所示:
$decorator = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'span', 'class'=> 'felement')),
// the next line is never applied
array('Label', array('tag' => 'span', 'class'=> 'fradio' , 'placement'=>'prepend') ),
array(array('row' => 'HtmlTag'), array('tag' => "div"))
);
$gender = new Zend_Form_Element_Radio("gender",
array(
"label"=>"Gender",
'multiOptions'=>array(
'male'=>'Male',
'female'=>'Female'
),
"decorators"=>$decorator
));
我得到了这个输出:
<dt id="gender-label">
<label class="optional">Gender</label>
</dt>
<!-- i don't know why the Main Label of the radio group didn't
have the Label decorator applied to it -->
<div>
<span class="felement">
<label for="gender-male"><input type="radio" disablefor="1" checked="checked" value="male" id="gender-male" name="gender">Male</label>
<label for="gender-female"><input type="radio" disablefor="1" value="female" id="gender-female" name="gender">Female</label>
</span>
</div>