gudmunson Posted March 30, 2007 Share Posted March 30, 2007 Hey guys, I have a question. I have an interesting scenario where I have multiple checkboxes sent via post to a next page. they are with name="checkbox1", name="checkbox2", etc. How do I access those on the next page? There could be quite a few of them, so I need to use a loop. I was hoping to access them via this method, but it doesn't seem to work. Any ideas? $_POST['checkbox' .$i] Link to comment https://forums.phpfreaks.com/topic/44968-_post-variable-question/ Share on other sites More sharing options...
kenrbnsn Posted March 30, 2007 Share Posted March 30, 2007 Change the names into arrays like: A <input name="checkbox[1]" type="checkbox" value="A"><br> B <input name="checkbox[2]" type="checkbox" value="B"><br> C <input name="checkbox[3]" type="checkbox" value="C"><br> D <input name="checkbox[4]" type="checkbox" value="D"><br> Then you can access them like: <?php if (isset($_POST['checkbox'])) foreach ($_POST['checkbox'] as $k => $v) echo 'Checkbox ' . $k . ' was checked. The value is ' . $v . '<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/44968-_post-variable-question/#findComment-218308 Share on other sites More sharing options...
fert Posted March 30, 2007 Share Posted March 30, 2007 foreach($_POST as $key=>$value) { if(strstr("checkbox",$key)) { $checkboxes[]=$value; } } print_r($checkboxes); This code will give you an array of the checkboxes in the checkboxes array Link to comment https://forums.phpfreaks.com/topic/44968-_post-variable-question/#findComment-218309 Share on other sites More sharing options...
gudmunson Posted March 30, 2007 Author Share Posted March 30, 2007 Thanks, guys. Link to comment https://forums.phpfreaks.com/topic/44968-_post-variable-question/#findComment-218315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.