当前位置:主页 > 软件编程 > PHP代码 >

PHP中CheckBox多选框上传失败的代码写法

时间:2021-06-29 08:27:55 | 栏目:PHP代码 | 点击:

用惯Java和其他语言的时候,表单上传只需要checkbox的name相同的时候就可以上传了

<input type="checkbox" name="checkbox" value="1"> 选项
<input type="checkbox" name="checkbox" value="2"> 选项
<input type="checkbox" name="checkbox" value="3"> 选项
<input type='button' value='确定' onclick="fun()"/>

但是PHP却只有在这种情况下,name要写成数组形式才能正常表单提交

<input type="checkbox" name="checkbox[]" value="1"> 选项1
<input type="checkbox" name="checkbox[]" value="2"> 选项2
<input type="checkbox" name="checkbox[]" value="3"> 选项3
<input type="checkbox" name="checkbox[]" value="4"> 选项4
<input type="checkbox" name="checkbox[]" value="5"> 选项5
<input type="checkbox" name="checkbox[]" value="6"> 选项6
<input type='button' value='确定' onclick="fun()"/>

下面给大家补充PHP处理Checkbox复选框表单提交问题

PHP表单提交页面复选框的名称后要加[],这样在接收页面才能得到正确的结果。表单提交后得到的是一个数组,然后通过访问数组元素得到表单的具体vaule值。得到的checkbox1的值,默认有</br>换行。

表单代码:

<form action="" method="post" name="asp"> 
  复选框1:<input type="checkbox" name="checkbox1[]" value="1" /> 
  复选框2:<input type="checkbox" name="checkbox1[]" value="2" /> 
  复选框3:<input type="checkbox" name="checkbox1[]" value="3" /> 
  <input type="submit" name= "Download" vaue="Download" /> 
 </form> 

PHP处理表单代码:

<?php 
   if(isset($_POST["Download"])) 
   { 
     foreach($_REQUEST['checkbox1'] as $checkbox1) 
     { 
          echo $checkbox1; 
     } 
   } 
?> 

您可能感兴趣的文章:

相关文章