将选择框分组到数组中进行发布?
我知道如何通过多选表单对象发送数据并将数据分组到一个数组中:
<select name="my_data[]" multiple="multiple"/>
是否可以有多个具有“单个”值的不同选择框并将它们全部推入一个数组中?即
<select id="select-1" name="my_data[]"/>
<select id="select-2" name="my_data[]"/>
结果将是
[
0 => {value of select-1},
1 => {value of select-2}
]
如果不可能的话,将选择的数据组合到数组中的好方法是什么?
I know how to send data via a multi-select form object and group the data into an array:
<select name="my_data[]" multiple="multiple"/>
Is it possible to have multiple different select boxes with "single" values and push them all into an array? i.e.
<select id="select-1" name="my_data[]"/>
<select id="select-2" name="my_data[]"/>
result would be
[
0 => {value of select-1},
1 => {value of select-2}
]
What would be a good way to combine the data from the selects into an array if not possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
啊,仅仅删除多个似乎就可以了。当表单元素名称中包含“[]”时,Zend Framework 的 FormSelect 帮助程序会自动添加它,但我没有意识到这一点。
Ah, just removing multiple seems to work. Zend Framework's FormSelect helper automatically added it when you have "[]" in your form element name and I did not realize that.
假设您正在获取页面上的所有
This assume you're getting all
<select>
's on the page:虽然你可能可以做到,但我不推荐它。只是因为其他人阅读代码并不清楚。
更好的方法就是在服务器端将它们组合起来。假设:
在 PHP 端:
While you probably can do it I wouldn't recommend it. Just because it isn't that clear from someone else reading the code.
A better approach is simply to combine them serverside. Assuming:
On the PHP side: