Précédent   Forum des professionnels en informatique > PHP > Langage > Formulaires
Formulaires Forum d'entraide sur les formulaires avec PHP. Avant de poster -> FAQ formulaires, Cours de formulaires et Sources de formulaires
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 05/06/2008, 10h56   #1
Invité régulier
 
Inscription : mai 2008
Messages : 41
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 41
Points : 7
Points : 7
Par défaut Condition sur contenu d'un champ

Bonjour, j'ai un ptit souci.
J'ai un formulaire ou l'on check les application qu'on souhaite et ou on rentre notre login :
Code :
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
 
<form action="form.php" method="post" name="monform">
<?php
	 include("../Connections/connec.php");
mysql_select_db('satisfaction')  or die('Erreur de selection '.mysql_error());
	 $result = mysql_query("SELECT nom_appli FROM appli");
		 while ($row = mysql_fetch_array($result))  
		 {
		 echo "<b>";
		 echo $row["nom_appli"];
		 echo " :</b>";
		 echo "<input type=\"checkbox\" name=\"";
		 echo $row["nom_appli"]; 
		 echo "\"><br>";
		 }
		 echo "</td><td align=\"right\">";
		 $result1 = mysql_query("SELECT nom_appli_fr FROM appli_fr");
		 while ($row = mysql_fetch_array($result1))  
		 {
		 echo "<b>";
		 echo $row["nom_appli_fr"];
		 echo " :</b>";
		 echo "<input type=\"checkbox\" name=\"";
		 echo $row["nom_appli_fr"]; 
		 echo "\"><br>";
		 }
		 echo "</td>";
		 mysql_close();
	 ?>
     </tr>
     </table>
     <br><br>
     <p align="center"><input name="login" type="text" />
     <br>
     <button style="cursor:hand; background:navy; color:white; border:solid 1px black;" type="submit">Commencer</button></p>
            </form>
et ensuite cela l'envoi vers un autre formulaire qui doit recuperer les application checké par l'utilisateur :
Code :
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
 
<form action="Add.php" method="post" name="monform2" onsubmit="return donneavis()">
<?php 
		 include("../Connections/connec.php");
mysql_select_db('satisfaction')  or die('Erreur de selection '.mysql_error());
$result = mysql_query("SELECT nom_appli FROM appli");
		 while ($row = mysql_fetch_array($result))  
		 {
		 if(document.monform.$row["nom_appli"].checked==true)
		 {
		echo "Pour l'application <b>"; 
		echo $row["nom_appli"];
		echo "</b> vous êtes :<br><br>"; 
		echo "<table width=\"600\">
		<tr>
		<td align=\"center\">";
	 echo "
	 <button style=\"cursor:hand; background:crimson; color:white; border:solid 1px black;\" type=\"button\" disabled >Très insatisfait</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:firebrick; color:white; border:solid 1px black;\" type=\"button\" disabled >Insatisfait</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:tan; color:white; border:solid 1px black;\" type=\"button\" disabled >Moyen</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:greenyellow; color:white; border:solid 1px black;\" type=\"button\" disabled >Bien</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:forestgreen; color:white; border:solid 1px black;\" type=\"button\" disabled >Exellent</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:grey; color:white; border:solid 1px black;\" type=\"button\" disabled >Non utilisé</button>";
		echo "</td>
		</tr>
		<tr>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"1\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"2\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"3\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"4\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"5\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"NULL\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "</tr>
		</table>
		<br>";
		}
	 }
Voila, c'est a mon avis cette ligne la qui plante :
Code :
1
2
 
if(document.monform.$row["nom_appli"].checked==true)
Cela ne doit pas etre la bonne syntaxe, il me met aucune erreur, mais le probleme c'est qu'il me met toutes les applications alors que je ne les ait pas toutes coché au formulaire precedent
Titus94120 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/06/2008, 11h23   #2
Modératrice
 
Avatar de Celira
 
Femme
Développeuse PHP/Java
Inscription : avril 2007
Messages : 3 686
Détails du profil
Informations personnelles :
Sexe : Femme
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeuse PHP/Java

Informations forums :
Inscription : avril 2007
Messages : 3 686
Points : 5 453
Points : 5 453
Ouh la ! c'est normal que ça plante, ce que tu testes n'est pas du php mais du javascript (enfin du javascript mélangé à une variable php)

Pour tester en php si une checkbox nom a été coché, il faut tester l'existence de la variable $_POST['nom']. Si la check box n'est pas cochée, la variable n'est pas créée...
donc ta condition devrait être :
Code :
if(isset($_POST[$row["nom_appli"]]))
__________________
Modératrice PHP
Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)

Pour afficher votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur)
Celira est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/06/2008, 11h24   #3
Membre éprouvé
 
Avatar de Sayrus
 
Inscription : décembre 2005
Messages : 818
Détails du profil
Informations personnelles :
Âge : 27

Informations forums :
Inscription : décembre 2005
Messages : 818
Points : 456
Points : 456
Code :
if(document.monform.$row["nom_appli"].checked==true)
C'est une synthaxe javascript mélangée à du PHP ça non?

J'ai jamais vu qu'on pouvait faire un document.monform en PHP

Alors il faudra traiter en PHP la variablé passée en argument
Code :
1
2
 
if($_POST['nom_appli']=='on')
__________________
Solutions pour concessions et garages automobiles =>
http://www.fastback.be
Sayrus est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/06/2008, 11h31   #4
Invité régulier
 
Inscription : mai 2008
Messages : 41
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 41
Points : 7
Points : 7
Merci celira

PS : Je savais que c'était du javascript mais je savais pas le remplacer en php
En tout cas merci.
Titus94120 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/06/2008, 13h54   #5
Invité régulier
 
Inscription : mai 2008
Messages : 41
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 41
Points : 7
Points : 7
Re petite question quand le nom de l'application n'est pas en un seul mot il ne me l'affiche pas dans le formulaire.

Comment ca se fait ?
Il faut mettre des guillemets, apostrophes, ... ?

Code :
echo $row["nom_appli"];
Titus94120 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/06/2008, 14h25   #6
Modératrice
 
Avatar de Celira
 
Femme
Développeuse PHP/Java
Inscription : avril 2007
Messages : 3 686
Détails du profil
Informations personnelles :
Sexe : Femme
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeuse PHP/Java

Informations forums :
Inscription : avril 2007
Messages : 3 686
Points : 5 453
Points : 5 453
ça veut dire que tu as des checkboxs qui ont un nom avec un espace dedans ? Je suis pas sure que ce soit autorisé... Tu pourrais peut-être replacer l'espace par un Underscore, pour éviter les problèmes.
[EDIT] ce n'est pas autorisé du tout donc tu n'as pas le choix il faut remplacer[/EDIT]
__________________
Modératrice PHP
Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)

Pour afficher votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur)
Celira est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/06/2008, 14h36   #7
Invité régulier
 
Inscription : mai 2008
Messages : 41
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 41
Points : 7
Points : 7
D'accord celira merci pour cette explication
Titus94120 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/06/2008, 17h11   #8
Invité régulier
 
Inscription : mai 2008
Messages : 41
Détails du profil
Informations forums :
Inscription : mai 2008
Messages : 41
Points : 7
Points : 7
Celira tu pourras encore peut etre m'aidé car une fois que j'arrive dans le formulaire avec les boutons radios, je voudrais vérifier que l'utilisateur ait bien mis une reponse pour toute les questions.
Je pense qu'il faut faire une fonction ? avec le bouton submit (onclick) ?

Code :
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
 
<form action="Add.php" method="post" name="monform2" onsubmit="return donneavis()">
<?php 
		 include("../Connections/connec.php");
mysql_select_db('satisfaction')  or die('Erreur de selection '.mysql_error());
$result = mysql_query("SELECT nom_appli FROM appli");
		 while ($row = mysql_fetch_array($result))  
		 {
		 if(isset($_POST[$row["nom_appli"]]))
		 {
		echo "Pour l'application <b>"; 
		echo $row["nom_appli"];
		echo "</b> vous êtes :<br><br>"; 
		echo "<table width=\"600\">
		<tr>
		<td align=\"center\">";
	 echo "
	 <button style=\"cursor:hand; background:crimson; color:white; border:solid 1px black;\" type=\"button\" disabled >Très insatisfait</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:firebrick; color:white; border:solid 1px black;\" type=\"button\" disabled >Insatisfait</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:tan; color:white; border:solid 1px black;\" type=\"button\" disabled >Moyen</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:greenyellow; color:white; border:solid 1px black;\" type=\"button\" disabled >Bien</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:forestgreen; color:white; border:solid 1px black;\" type=\"button\" disabled >Exellent</button>
	 </td>";
		echo "</tr>
		<tr>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"1\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"2\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"3\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"4\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"5\" name=\"";
		echo $row["nom_appli"]; 
		echo "\"></td>";
		echo "</tr>
		</table>
		<br>";
		}
	 }
	$result3 = mysql_query("SELECT nom_appli_fr FROM appli_fr");
		 while ($row = mysql_fetch_array($result3))  
		 {
		 if(isset($_POST[$row["nom_appli_fr"]]))
		 {
		echo "Pour l'application <b>"; 
		echo $row["nom_appli_fr"];
		echo "</b> vous êtes :<br><br>"; 
		echo "<table width=\"600\">
		<tr>
		<td align=\"center\">";
	 echo "
	 <button style=\"cursor:hand; background:crimson; color:white; border:solid 1px black;\" type=\"button\" disabled >Très insatisfait</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:firebrick; color:white; border:solid 1px black;\" type=\"button\" disabled >Insatisfait</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:tan; color:white; border:solid 1px black;\" type=\"button\" disabled >Moyen</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:greenyellow; color:white; border:solid 1px black;\" type=\"button\" disabled >Bien</button>
	 </td>";
	 echo "<td align=\"center\">
	 <button style=\"cursor:hand; background:forestgreen; color:white; border:solid 1px black;\" type=\"button\" disabled >Exellent</button>
	 </td>";
		echo "</tr>
		<tr>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"1\" name=\"";
		echo $row["nom_appli_fr"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"2\" name=\"";
		echo $row["nom_appli_fr"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"3\" name=\"";
		echo $row["nom_appli_fr"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"4\" name=\"";
		echo $row["nom_appli_fr"]; 
		echo "\"></td>";
		echo "<td align=\"center\">
		<input type=\"radio\" value=\"5\" name=\"";
		echo $row["nom_appli_fr"]; 
		echo "\"></td>";
		echo "</tr>
		</table>
		<br>";	
		}							
	 }
	 mysql_close();
	 ?>
          </br>
          <input type="submit" value="Envoyer" style="cursor:hand; background:navy; color:white; border:solid 1px black;">
          <input type="reset" value="Recommencer" style="cursor:hand; background:navy; color:white; border:solid 1px black;">   
            </form>
Titus94120 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h54.


 
 
 
 
Partenaires

Hébergement Web