我得到了这个表格:
<form method="post" action="" accept-charset="utf-8">
<p>
<label>first_field</label><br />
<input type="text" id="first_field" name="points[]" /><br />
<input type="radio" value="inside" name="group_1" checked /><br />
<input type="radio" value="outside" name="group_1"><br />
</p>
<p>
<label>second_field</label><br />
<input type="text" id="second_field" name="points[]" /><br />
<input type="radio" value="inside" name="group_2" checked /><br />
<input type="radio" value="outside" name="group_2"><br />
</p>
</form>
Run Code Online (Sandbox Code Playgroud)
我想要完成的是检查内部或外部是否被检查,如果在外面我检查给定文本输入的乘法点为1.5.BTW需要用PHP计算.
我怎样才能做到这一点?
Array
(
[bonus] => Array
(
[points] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
[10] => 0
[11] => 0
[12] => 0
[13] => 0
[14] => 0
)
[group] => Array
(
[0] => inside
[1] => outside
[2] => outside
[3] => inside
[4] => inside
[5] => inside
[6] => inside
[7] => inside
[8] => outside
[9] => inside
[10] => inside
[11] => inside
[12] => outside
[13] => inside
[14] => inside
)
)
)
Run Code Online (Sandbox Code Playgroud)
以上是print_r($ _ POST)的结果
现在我要将点数组与Group数组进行比较/删除,这样:
points [0]与组[0]等"连接"?
Dom*_*nes 69
事实证明,您可以使用HTML表单对字段进行分组.在这里查看此代码:(特别注意name属性)
<form method="post" action="" accept-charset="utf-8">
<p>
<label>first_field</label><br />
<input type="text" id="first_field" name="field[1][points]" /><br />
<input type="radio" value="inside" name="field[1][group]" checked /><br />
<input type="radio" value="outside" name="field[1][group]"><br />
</p>
<p>
<label>second_field</label><br />
<input type="text" id="second_field" name="field[2][points]" /><br />
<input type="radio" value="inside" name="field[2][group]" checked /><br />
<input type="radio" value="outside" name="field[2][group]"><br />
</p>
</form>
Run Code Online (Sandbox Code Playgroud)
如果没有填充任何内容,这将产生一个这样的POST数组:
Array
(
[field] => Array
(
[1] => Array
(
[points] =>
[group] => inside
)
[2] => Array
(
[points] =>
[group] => inside
)
)
)
Run Code Online (Sandbox Code Playgroud)
我希望这能回答你的问题,这是一个很好的小技巧,我没有看到很多人讨论过.需要注意的一点是,您需要在任何一组括号中手动指定ID号.您只能[]用作最后一组括号.
| 归档时间: |
|
| 查看次数: |
22034 次 |
| 最近记录: |