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
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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.