Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Re: [PHP] Unknown number of check boxes?
Old
  (#1)
Stephen
Guest
 
Posts: n/a
Default Re: [PHP] Unknown number of check boxes? - 06-02-2007, 07:55 PM

Søren Neigaard wrote:
> I would like to have a unknown number of generated check boxes like this:
>
> <input type="checkbox" name="chk01" />
> <input type="checkbox" name="chk02" />
> <input type="checkbox" name="chk0X" />
>
> And the name will be generated "chk01 to chk99", but how do I make the
> receiving PHP script that "scans" for post variables that are sent, so
> that I can work on this information?
>

The form posting agent will only return values for boxes that are checked.

You can do isset in a loop up to the maximum possible value.

But I suspect that you are generating the form dynamically. If that is
the case, add a hidden input with a value of the number of checkboxes.
That would be the upper limit of your loop.

Stephen
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Unknown number of check boxes?
Old
  (#2)
Kenoli
Guest
 
Posts: n/a
Default Re: Unknown number of check boxes? - 06-02-2007, 07:55 PM

Note the following: (from: http://us.php.net/manual/en/function...diff-***oc.php)

$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_***oc($array1, $array2);
print_r($result);

returns:

Array
(
[b] => brown
[c] => blue
[0] => red
)

If you have your script generate a php array that has all the checkbox
names as array values at the same time that it is generating the
checkbox html name attribute values, then you can make the above
comparison between the array you have created and the $_POST array.
The result will be an array of the names of the checkboxes that are
not checked. You can then extract them from this array as you desire
for whatever purpose you need them.

--Kenoli


On May 28, 11:51 am, stephe...@rogers.com (Stephen) wrote:
> Søren Neigaard wrote:
> > I would like to have a unknown number of generated check boxes like this:

>
> > <input type="checkbox" name="chk01" />
> > <input type="checkbox" name="chk02" />
> > <input type="checkbox" name="chk0X" />

>
> > And the name will be generated "chk01 to chk99", but how do I make the
> > receiving PHP script that "scans" for post variables that are sent, so
> > that I can work on this information?

>
> The form posting agent will only return values for boxes that are checked.
>
> You can do isset in a loop up to the maximum possible value.
>
> But I suspect that you are generating the form dynamically. If that is
> the case, add a hidden input with a value of the number of checkboxes.
> That would be the upper limit of your loop.
>
> Stephen



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top