发布多个多选框
我有一个表格,用于创建一周的时间范围。现在可以选择星期几、开始时间和结束时间。我有 javascript 附加一个相同形式的新分组,每个元素都用一个数组命名。
<label>Day Of Week:</label> <select name="dow[]" multiple="multiple" size="5"><option value="sun">sun</option><option value="mon">mon</option><option value="tue">tue</option><option value="wed">wed</option><option value="thu">thu</option><option value="fri">fri</option><option value="sat">sat</option></select><br />
<label>Start Time</label> Hour: <select name="starthour[]"><option value="0">12 AM</option><option value="1">1 AM</option><option value="2">2 AM</option><option value="3">3 AM</option><option value="4">4 AM</option><option value="5">5 AM</option><option value="6">6 AM</option><option value="7">7 AM</option><option value="8">8 AM</option><option value="9">9 AM</option><option value="10">10 AM</option><option value="11">11 AM</option><option value="12">12 PM</option><option value="13">1 PM</option><option value="14">2 PM</option><option value="15">3 PM</option><option value="16">4 PM</option><option value="17">5 PM</option><option value="18">6 PM</option><option value="19">7 PM</option><option value="20">8 PM</option><option value="21">9 PM</option><option value="22">10 PM</option><option value="23">11 PM</option></select>Minute: <select name="startmin[]"><option value="0">0</option><option value="15">15</option><option value="30">30</option><option value="45">45</option></select> <br />
<label>End Time</label> Hour: <select name="endhour[]"><option value="0">12 AM</option><option value="1">1 AM</option><option value="2">2 AM</option><option value="3">3 AM</option><option value="4">4 AM</option><option value="5">5 AM</option><option value="6">6 AM</option><option value="7">7 AM</option><option value="8">8 AM</option><option value="9">9 AM</option><option value="10">10 AM</option><option value="11">11 AM</option><option value="12">12 PM</option><option value="13">1 PM</option><option value="14">2 PM</option><option value="15">3 PM</option><option value="16">4 PM</option><option value="17">5 PM</option><option value="18">6 PM</option><option value="19">7 PM</option><option value="20">8 PM</option><option value="21">9 PM</option><option value="22">10 PM</option><option value="23">11 PM</option></select>Minute: <select name="endmin[]"><option value="0">0</option><option value="15">15</option><option value="30">30</option><option value="45">45</option></select> <br />
该表单是用 javascript 生成的,以便可以提交多个规则。除了多选框之外,一切正常。
如果用户在规则 1 中选择周一和周三,并在规则 2 中选择周二,它们将合并到表单上的同一数组中。因此 $_POST 的转储将显示:
Array ( [dow] => Array ( [0] => mon [1] => wed [2] => tue ) [starthour] => Array ( [0] => 0 [1] => 15 ) [startmin] => Array ( [0] => 0 [1] => 0 ) [endhour] => Array ( [0] => 5 [1] => 17 ) [endmin] => Array ( [0] => 0 [1] => 0 ) [do] => add [act] => scheduler [mod] => availability [avtype] => perm )
我无法确定 dow 中的数据来自哪个规则。我不相信我做了任何表面上错误的事情。目前我唯一的解决办法是只允许选择一天。然而,人们在多天内有相同的时间是很常见的。如果可能的话,最好包含此功能。
I have a form that I'm using to create time ranges throughout a week. Right now it is select the day of week, start time and end time. I have javascript appending a new grouping of this same form and each element is named with an array.
<label>Day Of Week:</label> <select name="dow[]" multiple="multiple" size="5"><option value="sun">sun</option><option value="mon">mon</option><option value="tue">tue</option><option value="wed">wed</option><option value="thu">thu</option><option value="fri">fri</option><option value="sat">sat</option></select><br />
<label>Start Time</label> Hour: <select name="starthour[]"><option value="0">12 AM</option><option value="1">1 AM</option><option value="2">2 AM</option><option value="3">3 AM</option><option value="4">4 AM</option><option value="5">5 AM</option><option value="6">6 AM</option><option value="7">7 AM</option><option value="8">8 AM</option><option value="9">9 AM</option><option value="10">10 AM</option><option value="11">11 AM</option><option value="12">12 PM</option><option value="13">1 PM</option><option value="14">2 PM</option><option value="15">3 PM</option><option value="16">4 PM</option><option value="17">5 PM</option><option value="18">6 PM</option><option value="19">7 PM</option><option value="20">8 PM</option><option value="21">9 PM</option><option value="22">10 PM</option><option value="23">11 PM</option></select>Minute: <select name="startmin[]"><option value="0">0</option><option value="15">15</option><option value="30">30</option><option value="45">45</option></select> <br />
<label>End Time</label> Hour: <select name="endhour[]"><option value="0">12 AM</option><option value="1">1 AM</option><option value="2">2 AM</option><option value="3">3 AM</option><option value="4">4 AM</option><option value="5">5 AM</option><option value="6">6 AM</option><option value="7">7 AM</option><option value="8">8 AM</option><option value="9">9 AM</option><option value="10">10 AM</option><option value="11">11 AM</option><option value="12">12 PM</option><option value="13">1 PM</option><option value="14">2 PM</option><option value="15">3 PM</option><option value="16">4 PM</option><option value="17">5 PM</option><option value="18">6 PM</option><option value="19">7 PM</option><option value="20">8 PM</option><option value="21">9 PM</option><option value="22">10 PM</option><option value="23">11 PM</option></select>Minute: <select name="endmin[]"><option value="0">0</option><option value="15">15</option><option value="30">30</option><option value="45">45</option></select> <br />
This form is generated with javascript so that multiple rules can be submitted. Everything works fine aside from the multiselect boxes.
If a user selected in rule one mon and wed, and in rule 2 selected tue, they get combined into the same array on the form. So a dump of $_POST will show:
Array ( [dow] => Array ( [0] => mon [1] => wed [2] => tue ) [starthour] => Array ( [0] => 0 [1] => 15 ) [startmin] => Array ( [0] => 0 [1] => 0 ) [endhour] => Array ( [0] => 5 [1] => 17 ) [endmin] => Array ( [0] => 0 [1] => 0 ) [do] => add [act] => scheduler [mod] => availability [avtype] => perm )
I have no way of determining which rule the data in dow is from. I don't believe I'm doing anything outwardly wrong. Currently the only fix I have is to only allow one day selected. However it is common that people have the same times over multiple days. It would be nice to include this functionality if at all possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的 javascript 中,使用 id 唯一地命名每个表单 - 如果有多个表单,这将起作用,但可能不是最佳解决方案。
也许最好的办法是在你的 javascript 表单生成中添加 var i;名称=i+“道[]”
这样您就可以识别各个表单元素。我不相信您可以区分同一表单上具有相同名称的表单元素,至少不能在帖子中区分。您可以使用 javascript pre-post 循环遍历这些元素,并在 post 上分配唯一标识符。
In your javascript, uniquely name each form with an id - this will work if there are multiple forms, but might not be the best solution.
maybe the best thing to do is in your javascript form generation, add var i; name=i+"dow[]"
so you can identify the individual form elements. I don't believe you can distinguish between form elements on the same form with the same name, at least not on post. You could loop through those elements with javascript pre-post and assign unique identifiers on post.
我会这样做。对于每个规则,我将获得一个时间戳,并且生成形式中的选择元素将如下所示。
因此,您的所有规则现在都将具有唯一的数组。
您可以使用以下代码获取时间戳。
I would do it this way.. for each rule i will get a timestamp and select element in generated form will look like this..
so all your rule will have unique array now.
you can get timestamp with following code.