So that in PHP I can deal with them as :
所以在PHP中我可以将它们作为:
foreach($_POST['checkboxname'] as $i => $value)
...
4 个解决方案
#1
36
Do something like this:
做这样的事情:
<input type="checkbox" name="checkboxArray[]" />
Note the [] in the name.
注意名称中的[]。
#2
12
Like this:
喜欢这个:
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
Just append [] to their names.
只需将[]附加到他们的名字即可。
#3
3
If you use an array for the checkboxes, you should add a value option as identifier for the single checkboxes, because then the returned array changes from Array ( [0] => on, [1] => on) to Array ( [0] => value1, [1] => value5 ), which let you identify the checked checkboxes.
如果对复选框使用数组,则应添加值选项作为单个复选框的标识符,因为返回的数组从Array([0] => on,[1] => on)更改为Array([0 ] => value1,[1] => value5),可以识别选中的复选框。
#4
1
for those HTML form elements that can send multiple values to server (like checkboxes, or multiple select boxes), you should use an array like name for your HTML element name. like this:
对于可以向服务器发送多个值的HTML表单元素(如复选框或多个选择框),您应该为HTML元素名称使用名称之类的数组。喜欢这个:
<input type="checkbox" name="checkboxname[]" />
also it is recommended that you use an enctype of "multipart/form-data" for your form element.
另外,建议您为表单元素使用“multipart / form-data”的enctype。
<form enctype="multipart/form-data" action="target.php" method="post">
then in your PHP scripts you can access the multiple values data as an array, just like you wanted.
然后在PHP脚本中,您可以像数组一样访问多个值数据,就像您想要的那样。
#1
36
Do something like this:
做这样的事情:
<input type="checkbox" name="checkboxArray[]" />
Note the [] in the name.
注意名称中的[]。
#2
12
Like this:
喜欢这个:
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
<input type="checkbox" name="checkboxname[]" />
Just append [] to their names.
只需将[]附加到他们的名字即可。
#3
3
If you use an array for the checkboxes, you should add a value option as identifier for the single checkboxes, because then the returned array changes from Array ( [0] => on, [1] => on) to Array ( [0] => value1, [1] => value5 ), which let you identify the checked checkboxes.
如果对复选框使用数组,则应添加值选项作为单个复选框的标识符,因为返回的数组从Array([0] => on,[1] => on)更改为Array([0 ] => value1,[1] => value5),可以识别选中的复选框。
#4
1
for those HTML form elements that can send multiple values to server (like checkboxes, or multiple select boxes), you should use an array like name for your HTML element name. like this:
对于可以向服务器发送多个值的HTML表单元素(如复选框或多个选择框),您应该为HTML元素名称使用名称之类的数组。喜欢这个:
<input type="checkbox" name="checkboxname[]" />
also it is recommended that you use an enctype of "multipart/form-data" for your form element.
另外,建议您为表单元素使用“multipart / form-data”的enctype。
<form enctype="multipart/form-data" action="target.php" method="post">
then in your PHP scripts you can access the multiple values data as an array, just like you wanted.
然后在PHP脚本中,您可以像数组一样访问多个值数据,就像您想要的那样。