由于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 id="form1" name="form1" method="post" action="?action=submit"> 河北 <label> <input type="checkbox" id="area" name="area[]" value="河北"> </label> 河南 <label> <input type="checkbox" id="area[]" name="area[]" value="河南"> </label> 山西 <label> <input type="checkbox" id="area[]" name="area[]" value="山西"> </label> 山东 <label> <input type="checkbox" id="area[]" name="area[]" value="山东"> </label> 江苏 <label> <input type="checkbox" id="area[]" name="area[]" value="江苏"> </label> 浙江 <label> <input type="checkbox" id="area[]" name="area[]" value="浙江"> </label> <label> <input type="submit" name="Submit" value="提交"> </label> </form> </body> </html>
如何联系我:【万里虎】www.bravetiger.cn 【QQ】3396726884 (咨询问题100元起,帮助解决问题500元起) 【博客】http://www.cnblogs.com/kenshinobiy/