bioTINMAN Posted January 9, 2008 Share Posted January 9, 2008 I have a form which has checkboxes named check1, check2, check3 and so on, the number being decided by another php code. When this form submits values to another php code, how do i get it to search for all those checks at once? can I use a wildcard like $HTTP_POST_VARS['check%']; I did try ofcourse, but it didnt work out. Quote Link to comment https://forums.phpfreaks.com/topic/85209-iterating-through-_post/ Share on other sites More sharing options...
kenrbnsn Posted January 9, 2008 Share Posted January 9, 2008 You need to put your check in a loop. The following code snippet assumes you know the maximum number of checkboxes some how. <?php for ($i=1;$i<=$maxchecks;$i++) if (isset($_POST['check' . $i])) { // // do something // } ?> If you have control over the script that creates the form, changing the names of the checkboxes to be an array would greatly simplify the code: <?php foreach ($_POST['check'] as $cb) { // // do something // } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/85209-iterating-through-_post/#findComment-434720 Share on other sites More sharing options...
bioTINMAN Posted January 10, 2008 Author Share Posted January 10, 2008 ill go for the second one. I should have changed all those checkboxes to arrays, but it was easier to do it the way I did. But now ill find a way around. So there is actually no way to use any wildcards in the field name afterall, is there? Quote Link to comment https://forums.phpfreaks.com/topic/85209-iterating-through-_post/#findComment-435147 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.