我得到了这个表格:
<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>
我想要完成的是检查是否检查了内部或外部,如果在外部,我检查了给定文本输入的乘积点 1,5。顺便说一句,这需要用 PHP 来计算。
我怎样才能做到这一点?
UPDATE
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
)
)
)
上面是 print_r($_POST) 的结果
现在我如何将点数组与组数组进行比较/配对:
点[0]“连接”到组[0]等?
事实证明,您可以使用 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>
如果不填写任何内容,这将产生一个如下所示的 POST 数组:
Array
(
[field] => Array
(
[1] => Array
(
[points] =>
[group] => inside
)
[2] => Array
(
[points] =>
[group] => inside
)
)
)
我希望这能回答你的问题,这是一个巧妙的小技巧,我还没有看到很多其他人讨论过。需要注意的一件事是,您需要在任意一组括号中手动指定 ID 号。您只能使用[]
作为最后一组括号。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)