[FX.php List] retrieving checkbox data

Michael Layne fx at 9degrees.com
Mon Jun 6 14:01:05 MDT 2005


I'm stuck... and maybe close...  I have lots of data I'm writing from  
either radio buttons or checkboxes.  I have no problem inputting the  
data -

if it's a checkbox (potential multiple answers), I do the name="answer 
[]"... etc.  I have these stored as "ABC, IMP, GES" - comma separated  
values.

When I retrieve this information to edit, I get the values and for  
radios:

$selection01 = array ('0' => '0-3','4' => '4-6','7' => '7-10','10' =>  
'10+');

     foreach($selection01 as $value => $label) {
     $checked = $data['answer01'][0] == $value ? " checked " : "";
         echo "<input name=\"answer01\" type=\"radio\" value=\"" .  
$value . "\" $checked />" . $label . "\n";
     }


I'm having difficulty with checkboxes...  I explode the values:

     $answer02 = explode("," , $dJP['answer02'][0]);

then I'm stuck...  an attempt:

$selection02 = array ('CPHB' => 'CPHB','NPDES' => 'NPDES','IRC' =>  
'IRC','CAPS' => 'CAPS','CGA' => 'CGA','CGB' => 'CGB','CGR' =>  
'CGR','GMB' => 'GMB');


     foreach($selection02 as $value => $label) {
         if ($answer02[0] == $value) {
         echo "<input name=\"answer02[]\" type=\"checkbox\" value= 
\"" . $value . "\" checked />" . $label . $i . "\n";
         } else {
         echo "<input name=\"answer02[]\" type=\"checkbox\" value= 
\"" . $value . "\" />" . $label . $i . "\n";
         }
     }

Can anyone help?  FM7SA, PHP 4.3.10 OS X.  I think I'm missing some  
loop, etc.

Thanks!

Michael


More information about the FX.php_List mailing list