我如何分组表单元素 [英] How can I group form elements
问题描述
< form method =postaction =accept-charset =utf -8\" >
< p>
< label> first_field< / label>< br />
< input type =textid =first_fieldname =points []/>< br />
< input type =radiovalue =insidename =group_1checked />< br />
< input type =radiovalue =outsidename =group_1>< br />
< / p>
< p>
< label> second_field< / label>< br />
< input type =textid =second_fieldname =points []/>< br />
< input type =radiovalue =insidename =group_2checked />< br />
< input type =radiovalue =outsidename =group_2>< br />
< / p>
< / form>
我想要完成的是检查是否检查了内部或外部,如果外部检查了乘法给定的文字输入点数为1,5。顺便说一句,这需要用PHP来计算。
我该怎么做?
UPDATE
数组
(
[bonus] =>数组
(
[points] = >数组
(
[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
($ b在
[1] =>以外
[2] =>以外
[3] =>以内
[4] = > insid e
[5] =>在
[6] =>内
[7] =>在
[8] =>在
之外[9] =>内
[10] =>内
[11] =>内
[12] =>在
之外[13] =>内
[14] =>内
)
)
)
以上是print_r($ _ POST)的结果
现在,我要比较/削减带有组数组的点数组:
points [0]获得连接到组[0]等。
事实证明,您可以使用HTML表单对字段进行分组。请在此处查看此代码:(特别注意 name
属性)
< form method =postaction =accept-charset =utf-8>
< p>
< label> first_field< / label>< br />
< input type =textid =first_fieldname =field [1] [points]/>< br />
< input type =radiovalue =insidename =field [1] [group]checked />< br />>
< input type =radiovalue =outsidename =field [1] [group]>< br />
< / p>
< p>
< label> second_field< / label>< br />
< input type =textid =second_fieldname =field [2] [points]/>< br />
< input type =radiovalue =insidename =field [2] [group]checked />< br />>
< input type =radiovalue =outsidename =field [2] [group]>< br />
< / p>
< / form>
没有填充任何内容,这会产生一个POST数组,如下所示:
数组
(
[field] =>数组
(
[1] =>数组
(
[points] =>
[group] =>里面
)
[2] =>数组
(
[points] =>
[group] =>内部
)
)
)
我希望这能回答你的问题,这是一个我并没有真正见过许多其他人讨论的巧妙小技巧。有一点需要注意的是,你需要在任何一组括号中手动指定一个ID号码。您只能使用 []
作为最后一组括号。
I got this form:
<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>
What i want to accomplish is to check if inside or outside is checked, if outside i checked the multiply points for the given text input by 1,5. BTW this needs to be calculated in PHP.
How can I do that?
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
)
)
)
Above is the result of print_r($_POST)
Now ho do I compare/pare The points array with the Group array so:
points[0] gets "connected" to group[0] etc.?
As it turns out, you can group fields using HTML forms. Check out this code here: (specifically note the name
attributes)
<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>
Without filling anything in, this will yield a POST array like this:
Array
(
[field] => Array
(
[1] => Array
(
[points] =>
[group] => inside
)
[2] => Array
(
[points] =>
[group] => inside
)
)
)
I hope this answered your question, it's a neat little trick I haven't really seen many others discuss. One thing to note is that you'll need to manually specify an ID number in that any set of brackets. You can only use []
as the last set of brackets.
这篇关于我如何分组表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!