Zend_Form_Element_Checkbox 问题

发布于 2024-12-23 04:42:00 字数 2214 浏览 5 评论 0原文

我想使用 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>

I want to achieve the example html markup using Zend_Form_Element_Checkbox. Encounter problems, however, for example page_actions[]. I want to have this in a attribute and receive array in request. I know I must do it in the init of the form, but I lack knowledge of Zend Framework. I tried several options. For example, this:

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

This is the markup I would like to achieve:-

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2024-12-30 04:42:00

您可以使用视图脚本来做到这一点。我认为 zend 表单装饰器不支持这种表单。

You can use view script to do that. I think zend form decorator is not support to this kind of form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文