Bonjour,
Voila mon petit souci : j'ai créé un formulaire d'inscription dans lequel on doit choisir un type de formation avec une liste déroulante. En fait quand la personne oublie de sélectionner un type, un message alert() est envoyé, cependant mon script d'inscription php s'exécute tout de même. Je sais que je devrais placer mon onsubmit dans <form> et non pas mettre un onclick dans un <input type="submit"> cependant je doit passer en paramètre une information tirées d'une requête SQL qui se déroule après le <form>...Enfin voila mon codeMerci d'avance pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349 <?php session_start(); if(isset($_SESSION['login_connexion']) && !empty($_SESSION['login_connexion'])) { ?> <html> <head> <title>Ajout d'habilitation</title> <script type='text/javascript'> function getXhr() { var xhr = null; if(window.XMLHttpRequest)// Firefox et autres { xhr = new XMLHttpRequest(); } else if(window.ActiveXObject)// Internet Explorer { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else // XMLHttpRequest non supporté par le navigateur { alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest"); xhr = false; } return xhr; } function go_niveau() { var xhr = getXhr(); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { leselect = xhr.responseText; document.getElementById('n').innerHTML = leselect; } } xhr.open("POST","menu_niveau.php",true); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); sel = document.getElementById('type'); id_type_formation_menu = sel.options[sel.selectedIndex].value; xhr.send("id_type_formation_menu="+id_type_formation_menu); } function confirmer(id_type_formation) { if(id_type_formation<=0) { alert('Attention : Vous devez choisir le type de formation'); } } </script> </head> <body> <h3>Ajout d'habilitation</h3> <form action="ajout_habilitation.php" method="POST"> <fieldset style="width:900px;"> <legend>Personne concernée</legend> <?php if(isset($_POST["id_personne"]) && !empty($_POST["id_personne"])) { $id_personne_post = $_POST["id_personne"]; $nom_post = $_POST["nom_personne"]; $prenom_post = $_POST["prenom_personne"]; $jour_naissance_post = $_POST["jour_naissance_personne"]; $mois_naissance_post = $_POST["mois_naissance_personne"]; $annee_naissance_post = $_POST["annee_naissance_personne"]; $Id = mysql_connect ("localhost" , "root" , ""); mysql_select_db ("suiviautorisation" , $Id) ; $ReqSQL = " SELECT * FROM `personne` WHERE id_personne='$id_personne_post'"; $Res = mysql_query ($ReqSQL, $Id); $Nb = mysql_num_rows($Res); if ( $Nb == 0 ) { echo ("Erreur"); } else { $Ligne = mysql_fetch_array($Res); echo("<input type=\"hidden\" name=\"id_personne\" value=\"".$id_personne_post."\"/> <table> <tr><td>Nom</td><td><input type=\"text\" name=\"nom_personne\" disabled=\"disabled\" value=\"".$Ligne["nom_personne"]."\"/></td></tr> <tr><td>Prénom</td><td><input type=\"text\" name=\"prenom_personne\" disabled=\"disabled\" value=\"".$Ligne["prenom_personne"]."\"/></td></tr> <tr><td>Date de naissance : </td><td><input type=\"text\" name=\"jour_naissance_personne\" disabled=\"disabled\" value=\"".$Ligne["jour_naissance_personne"]." / ".$Ligne["mois_naissance_personne"]." / ".$Ligne["annee_naissance_personne"]."\"/> </tr></table>"); } mysql_free_result($Res); mysql_close (); } else { echo("Erreur de transmission<br/><a href=\"formulaire_recherche_ajout.php\">Retour</a>"); } ?> </fieldset> <br/> <fieldset style="width:900px;"> <legend>Renseignements sur la formation</legend> Type : <select name="type_formation" id="type" onchange="go_niveau()"> <?php $Id = mysql_connect('localhost','root',""); mysql_select_db("suiviautorisation",$Id); $ReqSQL = "SELECT * FROM `type_formation_menu` ORDER BY `id_type_formation_menu`"; $Res = mysql_query($ReqSQL); if($Res == false) { echo ("Erreur requete"); } while ($Ligne = mysql_fetch_array($Res)) { echo("<option value=\"".$Ligne["id_type_formation_menu"]."\">".$Ligne["type_formation_menu"]."</option>"); $a = $Ligne["id_type_formation_menu"]; } mysql_close($Id); ?> </select> <div id="n"> Niveau : <select name="niveau_formation"> <option value="-1" selected="selected">-- Choisir un niveau --</option> </select> <br/> Spécification : <select name="specification_formation_1"> <option value="-1" selected="selected">-- Choisir une spécification --</option> </select> <br/> Spécification : <select name="specification_formation_2"> <option value="-1" selected="selected">-- Choisir une spécification --</option> </select> <br/> Spécification : <select name="specification_formation_3"> <option value="-1" selected="selected">-- Choisir une spécification --</option> </select> </div> <table> <tr> <td>Date de formation : </td> <td> <select name="jour_formation"> <?php for($j=1 ; $j<32 ; $j++) { echo("<option value=\"$j\">$j</option>"); } ?> </select> / <select name="mois_formation"> <?php for($m=1 ; $m<13 ; $m++) { echo("<option value=\"$m\">$m</option>"); } ?> </select> / <select name="annee_formation"> <?php for($a=1980 ; $a<2010 ; $a++) { echo("<option value=\"$a\">$a</option>"); } ?> </select> </td> </tr> <tr> <td>Durée de validité ( en années ) : </td> <td><input type="text" name="validite_formation"/></td> </tr> <tr> <td>Fin de validité : </td> <td><input type="text" name="fin_validite" disabled="disabled" /></td> </tr> <tr> <td>Lieu de formation : </td> <td><input type="text" name="lieu_formation"/></td> </tr> <tr> <td>Organisme évaluateur : </td> <td><input type="text" name="organisme_evaluateur_formation"/></td> </tr> </table> </fieldset> <br/> <fieldset style="width:900px;"> <legend>Renseignements sur l'entreprise</legend> <table> <tr> <td>Nom de la société : </td> <td><input type="text" name="nom_societe"/></td> </tr> <tr> <td>Nom de l'employeur : </td> <td><input type="text" name="nom_employeur_societe"/></td> </tr> </table> </fieldset> <table> <tr> <td> <br/><a href="formulaire_recherche_ajout.php">Retour</a> <input type="reset"/> <input type="submit" value="Enregistrer" onclick="confirmer('<?php $a; ?>')"/> </td> </tr> </table> <br/><br/><a href="deconnexion.php">Déconnexion</a> </form> </body> </html> <?php } else { header("Location: ../index.php"); } ?>
Partager