由于checkbox属性,所有必须把checkbox复选择框的名字设置为一个如果checkbox[],php才能读取,以数据形式,否则不能正确的读取checkbox复选框的值哦。

<form name="form1" method="post" action="">
<label><input type="checkbox" name="checkbox[]" value="复选一"></label>
<label><input type="checkbox" name="checkbox[]" value="复选二"></label>复选二
<label><input type="checkbox" name="checkbox[]" value="复选三"></label>复选三
<label><input type="checkbox" name="checkbox[]" value="复选四"></label>复选四

 

<label><input type="submit" name="Submit" value="提交"></label>
</form>
<?php
if( $_POST )
{
$value = $_POST['checkbox'];
echo '你的选择:'.implode(',',$value);
}
?>

 

checkbox在php读取值时要用数组形式哦,我们读取这些值用php post获取是以一个array形式哦

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>php获取多选框checkbox值</title> 
</head> 
<body> 
<?php 
$area_arr = array(); 
if($_GET['action']=="submit"){ 
$area_arr = $_POST['area']; 
} 
echo "您选定的地区为: "; 
foreach ($area_arr as $k=>$v){ 
echo $v." "; 
} 
?> 
<form > 
 河北 
<label> 
<input type="checkbox" > 
</label> 
  
 河南 
<label> 
<input type="checkbox" > 
</label> 
  
 山西 
<label> 
<input type="checkbox" > 
</label> 
  
 山东 
<label> 
<input type="checkbox" > 
</label> 
  
 江苏 
<label> 
<input type="checkbox" > 
</label> 
  
 浙江 
<label> 
<input type="checkbox" > 
</label> 
  
  
<label> 
<input type="submit" name="Submit" value="提交"> 
</label> 
  
</form> 
</body> 
</html> 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-01-10
  • 2021-12-06
猜你喜欢
  • 2022-12-23
  • 2022-03-01
  • 2022-01-19
  • 2022-03-06
  • 2021-12-23
  • 2021-12-06
  • 2022-12-23
相关资源
相似解决方案