Zend_Form :带有复选框的数据表
我希望在表单元素中有一个来自数据库的数据表,如下所示:
+-----+-------------------------+-----------------------+
| | Number | Name |
+-----+-------------------------+-----------------------+
| [ ] | 123 | ABC |
+-----+-------------------------+-----------------------+
| [x] | 456 | DEF |
+-----+-------------------------+-----------------------+
| [x] | 789 | HIJ |
+-----+-------------------------+-----------------------+
它将允许选择多行,例如 MultiCheckBox 元素。
这是我想要的标记类型:
<table>
<thead>
<tr>
<th>Select</th>
<th>Number</th>
<th>Name</th>
</tr>
</thead>
<tr>
<td><input type="checkbox" name="subscribers[]" value="1234"></td>
<td>1234</td>
<td>ABC</td>
</tr>
<tr>
<td><input type="checkbox" name="subscribers[]" value="375950"></td>
<td>375950</td>
<td>DEF</td>
</tr>
<!-- and so on... -->
我可以手动完成,但使用 Zend_Form 可以让我填充表单、轻松检索值并进行验证。我的形式中还有其他正常元素。
关于如何使用 Zend_Form 实现这一点有什么想法吗?也许是自定义元素和装饰器?
谢谢。如果需要,请询问更多信息。
这个问题似乎是相关的: Zend_Form: HTML table 中的数据库记录带复选框
Marc
I'd like to have a table of data coming from the DB in my form element, looking like the following :
+-----+-------------------------+-----------------------+
| | Number | Name |
+-----+-------------------------+-----------------------+
| [ ] | 123 | ABC |
+-----+-------------------------+-----------------------+
| [x] | 456 | DEF |
+-----+-------------------------+-----------------------+
| [x] | 789 | HIJ |
+-----+-------------------------+-----------------------+
It would allow to select several rows, like the MultiCheckBox element.
Here is the kind of markup I would like to have:
<table>
<thead>
<tr>
<th>Select</th>
<th>Number</th>
<th>Name</th>
</tr>
</thead>
<tr>
<td><input type="checkbox" name="subscribers[]" value="1234"></td>
<td>1234</td>
<td>ABC</td>
</tr>
<tr>
<td><input type="checkbox" name="subscribers[]" value="375950"></td>
<td>375950</td>
<td>DEF</td>
</tr>
<!-- and so on... -->
I can do it by hand but using Zend_Form would allow me to populate the form, retrieve the values easily and to have validation. I have other normal elements in my form.
Any idea on how to achieve this with Zend_Form ? Maybe a custom element and decorator ?
Thanks. Ask for more info if needed.
This question seems to be related: Zend_Form: Database records in HTML table with checkboxes
Marc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这将是一个更长的表格
答案
控制器
查看
这里发生了一些事情。
我从表单对象中获取预填充的值:
<代码>
<代码>
我根据上面的数组将每个复选框标记为已选中或未选中
编辑回复评论 B/C 评论不支持预块
或
只接受 key =
>值对,因此您想要在键值对之外执行的任何操作都会有点奇怪。如果您的程序允许您可以将另一个变量传递给视图,则该数组使用与 multiCheckbox 相同的键,因此
然后在视图中的 foreach 中使用
ok, so this is going to be a longer sort of answer
the Form
Controller
View
A couple things are happening here.
I get the prepopulated values out of the form object:
I mark each checkbox as checked or not based on the array above
EDIT IN RESPONSE TO COMMENT B/C COMMENTS DON'T SUPPORT PRE BLOCKS
the
or
only accepts key => value pairs, so anything you want to do outside of key value pairs is going to be a little wierd. If your program allows you could pass another variable to the view, an array that uses the same keys as the multiCheckbox so
and then in the foreach in the view use