PHP处理多个复选框

时间:2012-04-15 04:25:49

标签: php-5.3

好的,我的index.html表格如下:

<form action="process.php" method="post">
  <table>
    <tr>
      <td><input name="Field[]" type="checkbox" value="Accounting" />Accounting</td>
      <td><input name="Field[]" type="checkbox" value="Finance" />Finance</td>
      <td><input name="Field[]" type="checkbox" value="Marketing" />Marketing</td>
    </tr>
  </table>
</form>

我的process.php如下:

<table>
  <tr>
    <th>Field(s):</th>
    <td>
      <?php
        if(isset($_POST['Field']))
        {
          for($i = 0; $i < count($_POST['Field']); $i++)
          { echo $_POST['Field'][$i] . ' '; }
        }
      ?>
    </td>
  </tr>
</table>

但出于某种原因,我只得到打印出来的最后一个复选框的第一个字母。求救!

1 个答案:

答案 0 :(得分:5)

Try this one in process.php to get the values from $_POST['Field']

   <table>
    <tr>
     <th>Field(s):</th>
     <td>
      <?php
        if(isset($_POST['Field']))
        {
          foreach ($_POST['Field'] as $value) {
            echo $value;
          }
        }
      ?>
     </td>
    </tr>
   </table>