Bonjour et merci pour ta réponse.
Ben si je fais un
for($i=0; $i<count($_POST['xxxxxxx']); $i++){
je risque d'avoir x "for"!
En faisant ça:
for($i=0; $i<count($_POST); $i++){
je boucle seulement sur les champs qui existent dans mon formulaire (mais il est vrai que je ne prends pas en compte chaque éléments)
Et voici le code du formulaire:
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| <!DOCTYPE html>
<html lang="fr" class="no-js fond_site">
<body>
<?php
include 'fonctions.php';
$mysqli = connexion_BDD('localhost', 'xxxx', 'root', 'xxxx');
/*$id = $_GET['id_test'];
$choix = $_GET['sous_choix'];*/
$sql2 = "SELECT * ,\n"
. " CASE `choix_test`\n"
. " WHEN 'champ_texte' THEN 1\n"
. " WHEN 'zone_email' THEN 2\n"
. " WHEN 'liste' THEN 3\n"
. " WHEN 'bouton' THEN 4\n"
. " WHEN 'case' THEN 5\n"
. " WHEN 'zone_texte' THEN 6\n"
. " WHEN 'Titre' THEN 7\n"
. " END AS 'Status'\n"
. " FROM `test23` f"
. " LEFT JOIN `titre23` t ON f.`id_titre` = t.`id_titre`"
. " WHERE f.id_titre=" .$_GET['lastId']
;
$result = $mysqli->query($sql2);
$email = $_POST['reponse_email'];
/*if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'Cet email est correct.';
} else {
echo 'Cet email a un format non adapté.';
}*/
echo '<form id="idTest2" name="reponse" method="post" action="traitement_reponse.php">';
while($data = $result->fetch_array())
{
$chaine = $data['sous_choix'];
$list = explode(";", $chaine);
echo $data['nom_test']." ";
switch($data['Status']){
case 1:
echo '<input name="nom_reponse[]" type="text"/><br/>';
break;
case 2:
echo '<input name="reponse_email[]" type="email"/><br/>';
break;
case 3:
?>
<select name="reponse_select[]" id="select">
<?php
foreach($list as $value){
?>
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
<?php
}
?>
</select><br/>
<?php
break;
case 4:
foreach($list as $radio){
?>
<input type="radio" name="reponse_radio[]" value="<?php echo $radio; ?>"/><?php echo $radio; ?><br/>
<?php
}
break;
case 5:
foreach($list as $case){
?>
<input type="checkbox" name="reponse_case[]" value="<?php echo $case; ?>"/><?php echo $case; ?><br/>
<?php
}
break;
case 6:
echo '<textarea name="textarea_reponse[]" rows="4" cols="50"></textarea><br/>';
break;
case 7:
echo '<br/>';
break;
default:
echo "Oups! <br/>";
}
/* if ($data['Status'] == 1) {
echo "<input name=\"nom_reponse\" type=\"text\"/>";
} elseif ($data['Status'] == 2) {
echo "<input name=\"reponse_email\" type=\"text\"/>";
} elseif ($data['Status'] == 3) {
echo "<select name=\"reponse_select\" id=\"select\"><option value=\"\"></option></select>";
} elseif ($data['Status'] == 4) {
echo "<input type=\"radio\" name=\"reponse_radio\" value=\"\"/>";
} elseif ($data['Status'] == 5) {
echo "<input type=\"checkbox\" name=\"reponse_case\" value=\"\"/>";
} elseif ($data['Status'] == 6) {
echo "<textarea name=\"textarea_reponse\" rows=\"4\" cols=\"50\"></textarea>";
} else {
echo 'Oups';
}
echo "<br/>";*/
//echo $list;
/*echo $data['sous_choix']."<br/>";
print_r($data['sous_choix']);*/
}
echo '<input type="submit" value="envoyer" name="valider" style="margin-left: 435px;">';
echo '</form>';
?>
<br/><br/><br/>
<div id="retour">
<a href="Form.php?lastId=<?php echo $_GET['lastId']; ?>">Retour</a>
</div>
<?php
$result->close();
$mysqli->close();
?>
</body>
</html> |
Partager