Page 1 of 1

Multicheckbox

Posted: Sun Oct 18, 2009 5:14 am
by zeroc00l
hi guyz, I've a small problem, my form is of this kind:

In a while cicle I build my checkboxes:

Code: Select all

 
<td>    
        <input type="checkbox" name="selection'.$i.'['.$index1++.']" value="'.$i.'-1-1-'.$row_partite[7].'">
</td>
<td>
        <input type="checkbox" name="selection'.$i.'['.$index1++.']" value="'.$i.'-x-1-'.$row_partite[8].'">
</td> 
<td>
        <input type="checkbox" name="selection'.$i.'['.$index1++.']" value="'.$i.'-2-1-'.$row_partite[9].'">
</td>
 
So in the HTML page I have this:

[] with the name of "selection1[1]" - [] "selection1[2]" - [] "selection1[3]"
[] with the name of "selection2[1]" - [] "selection2[2]" - [] "selection2[3]"
[] with the name of "selection3[1]" - [] "selection3[2]" - [] "selection3[3]"
....

on the other page, when I send the form, I must have an array for each "selection n" and I must take also an array that has all the "selection n" alwais relative to the "selection n" that I send.

So this procedure must be dynamic for the memorization of the checkboxes, somebody can resolve this problem?

Obviously I know how to have a normal array of multicheckboxes, but transpose all of this dynamically is giving me a headshot!

HELP

Re: Multicheckbox

Posted: Sun Oct 18, 2009 9:44 am
by Eric!
Here's a generic way to process all the posted data. You can customize it or learn how to extract what you need by building the appropriate keys dynamically.

Code: Select all

foreach ($_POST as $key => $value)
{ 
   if (!is_array($value))
   { 
      $message .= "\n".$key." : ".$value; 
   } 
   else
   { 
      foreach ($_POST[$key] as $itemvalue)
      { 
         $message .= "\n".$key." : ".$itemvalue; 
      } 
   } 
}