Php 将值数组作为post数据传递给document.forms[]方法?

Php 将值数组作为post数据传递给document.forms[]方法?,php,javascript,Php,Javascript,在我的html中,我有这样一个 <tr> <td class="grid_cell" width="5%"> <input type="checkbox" name="workspace_trees_rpt_target" id="<?php echo $t["tree_id"];?>" value="<?php echo $t["tree_id"];?>" /> <

在我的html中,我有这样一个

    <tr>
        <td class="grid_cell" width="5%">
            <input type="checkbox" name="workspace_trees_rpt_target" id="<?php echo $t["tree_id"];?>" value="<?php echo $t["tree_id"];?>" />
        </td>
    </tr>
    if(confirm("Delete cannot be undone, click OK button to proceed.")) {
        document.forms[0].method="POST";
        document.forms[0].action="delete.php";
        document.forms[0].submit();     
    }

选中两个复选框并单击OK按钮后,我进入
delete.php
print\r
我的帖子数据。但是当显示打印的结果时,复选框只显示了一个值,但我希望有两个。如何使我选中多个复选框时,复选框的post数据将是选中复选框值的数组?

必须将输入的名称设置为数组:

name="workspace_trees_rpt_target[]"

您已为所有复选框指定了相同的名称。因此,只能返回一个值

改为

<input type="checkbox" name="workspace_trees_rpt_target[]" id="<?php echo $t["tree_id"];?>" value="<?php echo $t["tree_id"];?>" />
if ( isset( $_POST['workspace_trees_rpt_target'] ) ) {
    // at least one checkbox has been ticked
    foreach ( $_POST['workspace_trees_rpt_target']  as $checkboxe ) {
         // do whatever $checkbox it will be set to the value="" that you set earlier
    }
}