谁有好办法没?
我认为在名称不必用数组,这样在javascript 中好控制.
在Form 中隐藏一个值,来接受checkbox 中选中的值.
再在php中处理这个隐藏值即可.
测试如下:
<?
  if(!isset($page))
    {
       //界面
    ?>
<script language=javascript>
<!--
   function get_box_value(form)
    {
      var temp="";
      if(form.box1.select) //检查是否选中,若选中加入临时变量temp中
         temp+=form.box1.value+".";
      if(form.box2.select)
         temp+=form.box2.value+".";
      if(form.box3.select)
         temp+=form.box3.value;
      form.checkbox_str.value=temp;
  }
-->
</script>
<form action=<? echo $PHP_SELF; ?> method=post>
<input type=hidden name=page value=1>
<input type=hidden name=checkbox_str>
<input type=checkbox name=box1 value=a>aaa
<input type=checkbox name=box2 value=b>bbb
<input type=checkbox name=box3 value=c>ccc
<p>
<input type=submit value=ok onclick="get_box_value(this.form)">
</form>
<?
   }
   else
   {
      echo $checkbox_str;
    }
?>

解决方案 »

  1.   

    找了篇文章,共大家参考:
    ----------------------------------------------------------------- 
    用PHP处理多个同名复选框 如果一个表单中有多个同名复选框,在提交到php时却只有一个值,而并不像asp那样是一串用逗号分割的值。有一个很简单的方法来解决:将复选框的name后面加上[],例如:<input type="checkbox" name="ccc" value="1"> 改为:<input type="checkbox" name="ccc[]" value="1">。这样php将得到一个叫ccc的阵列。但这种方法有个问题,如果您要在客户端对复选框是否被选择、选择了几个用javascript来判断时,javascript会因为复选框的name中含有[]而出错。您可以在表单中加入一个隐含域,用javascript设置它的值。 <script language="javascript"> 
    function check() 

    var strchoice=""; 
    for(var i=0;i<document.news.choice.length;i++) 

    if (document.news.choice[i].checked) 

    strchoice=strchoice+document.news.choice[i].value+","; 


    if (!document.news.choice.length) 

    if (document.news.choice.checked) 

    strchoice=document.news.choice[i].value;+"," 


    strchoice=strchoice.substring(0,strchoice.length-1); 
    document.news.choiceid.value=strchoice; 
    alert(document.news.choiceall.value); 

    </script> 
    <html> 
    ... 
    <form name="news" action="test.php" method="post" onsubmit="check()"> 
    <input type="checkbox" name="choice" value="1"> 
    <input type="checkbox" name="choice" value="2"> 
    <input type="checkbox" name="choice" value="3"> 
    <input type="checkbox" name="choice" value="4"> 
    <input type="hidden" name="choiceid" value=""> 
    </form> 
    ... 
    </html> 
      

  2.   

    <form name="news" action="test.php" method="post" onsubmit="check()"> 
    <input type="checkbox" name="choice" value="1"> 
    <input type="checkbox" name="choice" value="2"> 
    <input type="checkbox" name="choice" value="3"> 
    <input type="checkbox" name="choice" value="4"> 
    <input type="hidden" name="choiceid" value=""> 
    </form> 此处的name="choice"改为choice[]比较好
    在php接收的时候,可以接收到一个数组javascript处理的时候可以如楼上所示
      

  3.   

    Attention : 
      当checkbox没有check的时候,它的值是不会传递过去的!
    如:
    <form name="news" action="test.php" method="post" onsubmit="check()"> 
    <input type="checkbox" name="choice[]" value="1"> 
    <input type="checkbox" name="choice[]" value="2"> 
    <input type="checkbox" name="choice[]" value="3"> 
    <input type="checkbox" name="choice[]" value="4"> 
    <input type="hidden" name="choiceid[]" value=""> 
    </form> 
    假如只check了第2、4个,则php接收到的数组会是:choice[0]=2,choice[1]=4
    ------------------------------------------------------------------------