1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
   | <?php
if (isset($_POST['mon_champ'])) {
    echo "Vous avez choisi :";
    for ($i = 0, $c = count($_POST['mon_champ']); $i < $c; $i++) {
        echo "<br/><b>" . $_POST['mon_champ'][$i] . "</b>";
    }
}
 
// Renvoie vrai si $option fait partie du résultat
function est_selectionne($option) {
    if (!isset($_POST['mon_champ'])) {
            return FALSE;
    }
    for ($i = 0, $c = count($_POST['mon_champ']); $i < $c; $i++) {
        if ($_POST['mon_champ'][$i] == $option) {
            return TRUE;
        }
    }
    return FALSE;
}
?>
 
<form method="POST">
  QUESTION 1     <input type="checkbox" name="mon_champ[]" value="30" <?php if(est_selectionne("Option 1")) { echo 'checked'; } ?>/>oui
       <input type="checkbox" name="mon_champ[]" value="0" <?php if(est_selectionne("Option 2")) { echo 'checked'; } ?>/>non
       <input type="checkbox" name="mon_champ[]" value="" <?php if(est_selectionne("Option 3")) { echo 'checked'; } ?>/>N/A
	   <input type="text" name="mon_champ[]" <?php echo $_POST['mon_champ'][$i]; ?> <?php if(est_selectionne("Option 4")) { echo 'checked'; } ?>/>
    <br /><br /><input type="submit" value="OK"/>
</form> | 
Partager