测试代码:<?php
   if($_REQUEST['test']){
     $t=$_REQUEST['test'];
     //echo $t;
     for($i=0;$i<count($t);$i++){
echo $t[$i].'<br />';
     }
   }
?>
<form name="testForm" method="get" action="">
   <input type="checkbox" name="test" value="1">
   <input type="checkbox" name="test" value="2">
   <input type="checkbox" name="test" value="3">
   <input type="checkbox" name="test" value="4">
   <input type="submit" value="ok" />
</form>很简单的代码,就是把已选择的checkbox的值打印出来,以前测试时是以数组的形式获得,但是现在再输出时却输出第一个被选择的值,害得我不得不在客户端强制把checkbox的值写成"val1,val2,val3,..."的形式后再提交给服务端处理,是什么问题呢,在服务端怎么获得已选择checkbox的所有的值?

解决方案 »

  1.   

    用JavaScript保存CheckBox的checked值为一个隐藏的文本值然后提交给PHP处理。
      

  2.   

    <form name="testForm" method="get" action=""> 
      <input type="checkbox" name="test[]" value="1"> 
      <input type="checkbox" name="test[]" value="2"> 
      <input type="checkbox" name="test[]" value="3"> 
      <input type="checkbox" name="test[]" value="4"> 
      <input type="submit" value="ok" /> 
    </form>