Je suis débutant en PHP et j'essaie de faire un formulaire d'évaluation. Le formulaire aura plusieurs questions sous ce format:
Question 1 oui non n/a et a la fin un textbox.
Lorsque le checkbox «oui» est sélectionné il affiche une valeur dans le textbox et même chose pour les autre checbox.
Voici ce que j'ai fait jusqu'ici mais malheureusement je ne suis pas capable de faire affiche la valeur dans le textbox.
Je vous remercie a l'avance pour votre aide
<?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>