1

I'm creating a CMS in which I have an overview of pages. I want the user to be able to mass delete these pages and so I have created a form in which each page has a checkbox with the pages database ID as value and name:

<input class="mass-delete-check" type="checkbox" name="<?=$page["id"]?>" value="<?=$page["id"]?>" id="<?=$page["id"]?>">

Now when I submit this form I need to get the values of the checkboxes that are actually checked and put them in an array I can go through to delete them. The thing here is that I will have to get checkbox values based on if they are checked and not on their name because I can't know all names.

Does anyone have a solution to this?

1 Answer 1

2

Use the same name for all checkboxes. So after submiting you will have array with page IDs to delete.

<input class="mass-delete-check" type="checkbox" name="delete_pages[]" value="<?=$page["id"]?>" id="<?=$page["id"]?>">

After submit you would get array of IDs with $_POST['delete_pages'], which contains actual page IDs what you need to delete.

Sign up to request clarification or add additional context in comments.

1 Comment

I should've thought of this. But thanks a lot for helping me out :)

Your Answer

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