houssam_ballout Posted February 8, 2008 Share Posted February 8, 2008 Hello all,I'd multiple checkboxs and radio buttons , and they are generated automatically based on the database that I'd (mysql)..on my page, I had queried all the questions and number of options, part of the code that I think you need is:for($i=1;$i<=$NbOptions;$i++){if($MultiAnswer == 'yes'){echo "<input type='checkbox' name='box[]' value='$idQuestion_$i' />" . $row2['option'.$i];echo "<br />";}else{echo "<input type='radio' name='box[]' value='' />" . $row2['option'.$i];echo "<br />";}}when I press save ,I useif(isset($_POST['save']))//here I want to loop through all the box[]?and see if its checked or no Link to comment Share on other sites More sharing options...
Lulzim Posted February 8, 2008 Share Posted February 8, 2008 In $_POST['box'] you will have values of checked checkboxes only, if a checkbox is not checked the form will not send the value for that checkbox to the script.here is an example for ($i=0; $i<count($_POST['box']; $i++){ $echo $_POST['box'][$i];} or foreach ($_POST['box] as $box){ $echo $box;} Link to comment Share on other sites More sharing options...
jhecht Posted February 8, 2008 Share Posted February 8, 2008 what lulzim said. But a pretty easy way to tell if its a checkbox or radio is to put in a hidden input tag that says something like echo "<input type=\"hidden\" value=\"$IsRadio\" name=\"checkOrRadio" />\n"; Where $IsRadio is some value defined in your script(usually a 1 or 0 works just fine, as they are the equivelent of true or false). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.