denno020 Posted December 18, 2011 Share Posted December 18, 2011 I've got a page that has a dynamic number of checkboxes. I'm trying to figure out how to process the form once submitted. I've got a foreach loop set up, but I need to know the id of the checkbox so that I can make the change to my database accordingly. At the moment, my form is built with the checkboxes given the name of "checkbox['$id']", where id is pulled from the database. In my parsing script, I've got this foreach loop that I found on the internet foreach($_POST["checkbox"] as $checkbox){ } But I don't know what to put in that foreach loop to be able to grab the id that the checkbox was given when the form was initially built? I'm struggling to find any examples on the Internet :/.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/253397-foreach-loop-processing-checkboxes/ Share on other sites More sharing options...
manny Posted December 18, 2011 Share Posted December 18, 2011 Here is an example how you can do that.. <input type="checkbox" name="checkbox[iD]" value="ID" /> <input type="checkbox" name="checkbox[135]" value="135" /> <?php $checkboxes = !empty($_POST['checkbox'])? $_POST['checkbox'] : array(); foreach ($checkboxes as $id => $value) { // code goes here... } ?> Let me know if this helps. Quote Link to comment https://forums.phpfreaks.com/topic/253397-foreach-loop-processing-checkboxes/#findComment-1298936 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.