Zend_Form_Element_Checkbox问题

时间:2011-12-27 17:27:23

标签: zend-framework zend-form

我想使用Zend_Form_Element_Checkbox实现示例html标记。然而,遇到问题,例如page_actions []。我希望在一个属性中有这个并在请求中接收数组。我知道我必须在表单的init中执行它,但我缺乏Zend Framework的知识。我尝试了几种选择。例如,这个:

// In for loop in init method
$element = new Zend_Form_Element_Checkbox('test['.$i.']');
$element->setIsArray(true)->setBelongsTo('checkbox_name');
$this->addElement($element);

这是我想要达到的标记: -

<div>
    <div>
        Some bold message for this group
    </div>
    <div>
        <span>
            <input type="checkbox" id="qf_18" value="12" name="page_actions[]"/><label for="qf_18">Test 18</label><br/>
            <input type="checkbox" id="qf_20" value="13" name="page_actions[]"/><label for="qf_20">Test 20</label><br/>
            <input type="checkbox" id="qf_22" value="14" name="page_actions[]"/><label for="qf_22">Test 22</label><br/>
            <input type="checkbox" id="qf_24" value="15" name="page_actions[]"/><label for="qf_24">Test 24</label><br/>
            <input type="checkbox" id="qf_26" value="16" name="page_actions[]"/><label for="qf_26">Test 26</label>
        </span>
    </div>
</div>
<div>
    <div style="font-weight: bold;">
        Some bold message for this other group
    </div>
    <div>
        <span>
            <input type="checkbox" id="qf_28" value="17" name="page_actions[]"/><label for="qf_28">Test 28</label><br/>
            <input type="checkbox" id="qf_30" value="18" name="page_actions[]"/><label for="qf_30">Test 30</label><br/>
            <input type="checkbox" id="qf_32" value="19" name="page_actions[]"/><label for="qf_32">Test 32</label><br/>
            <input type="checkbox" id="qf_34" value="20" name="page_actions[]"/><label for="qf_34">Test 34</label><br/>
            <input type="checkbox" id="qf_36" value="21" name="page_actions[]"/><label for="qf_36">Test 35</label>
        </span>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用视图脚本来执行此操作。我认为zend表单装饰器不支持这种形式。