0

In my html I have this,

    <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>

this are inside a loop so what will be displayed is a lot of checkboxes with different values. And in my script I have this,

    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();     
    }

after selecting two of the checkboxes and click the OK button, I then go to delete.php to print_r my post data. But when the result of print_r is displayed it only showed one value for the checked checkboxes, but I was expecting two of them. How can I make it such that when I check multiple checkboxes, the post data for the checkboxes will be an array of values of the checked checkboxes?

2 Answers 2

2

you must set the name of the inputs as array:

name="workspace_trees_rpt_target[]"
Sign up to request clarification or add additional context in comments.

Comments

0

You have given the same name to all of your checkboxes. So only one value can be returned.

Change to

<input type="checkbox" name="workspace_trees_rpt_target[]" id="<?php echo $t["tree_id"];?>" value="<?php echo $t["tree_id"];?>" />

Then in your PHP code you will get and array of $_POST['workspace_trees_rpt_target'][]

So process it like this:

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
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.