Jump to content

iterating through $_POST


bioTINMAN

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/85209-iterating-through-_post/
Share on other sites

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.