IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Soumission de form et alert()


Sujet :

JavaScript

  1. #1
    Membre averti
    Femme Profil pro
    ...
    Inscrit en
    Avril 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : ...

    Informations forums :
    Inscription : Avril 2009
    Messages : 49
    Par défaut Soumission de form et alert()
    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 code
    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&eacute;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&eacute;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&eacute;cification : 
     
    							<select name="specification_formation_1">
     
    								<option value="-1" selected="selected">-- Choisir une sp&eacute;cification --</option>
     
    							</select>
     
    							<br/>
     
    							Sp&eacute;cification : 
     
    							<select name="specification_formation_2">
     
    								<option value="-1" selected="selected">-- Choisir une sp&eacute;cification --</option>
     
    							</select>
     
    							<br/>
     
    							Sp&eacute;cification : 
     
    							<select name="specification_formation_3">
     
    								<option value="-1" selected="selected">-- Choisir une sp&eacute;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&eacute;e de validit&eacute; ( en ann&eacute;es ) : </td>
    								<td><input type="text" name="validite_formation"/></td>
     
    							</tr>
     
    							<tr>
     
    								<td>Fin de validit&eacute; : </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 &eacute;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&eacute;t&eacute; : </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&eacute;connexion</a>
     
    				</form>
     
    			</body>
     
    		</html>
     
    		<?php
                    
            }
            else
            {
                    header("Location: ../index.php");
            }
            
    ?>
    Merci d'avance pour votre aide

  2. #2
    Membre Expert
    Inscrit en
    Septembre 2002
    Messages
    2 307
    Détails du profil
    Informations forums :
    Inscription : Septembre 2002
    Messages : 2 307
    Par défaut
    se déroule après le <form>...
    -> revoir le sénario, il est bien compliqué ce que tu essaie de faire il semble que tu utilise ajax

  3. #3
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Par défaut
    merci de poster le code généré.

    sinon , il te suffit de vérifier tes données avant de les envoyer en ajax ...

  4. #4
    Membre averti
    Femme Profil pro
    ...
    Inscrit en
    Avril 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : ...

    Informations forums :
    Inscription : Avril 2009
    Messages : 49
    Par défaut
    Il n'existe vraiment pas un moyen de le placer au niveau du submit? J'avais essayé aussi de placer le test dans le script php de l'inscription : ça fonctionne mais je ne peux par faire de retour en arrière car le début du formulaire est créé par SQL et donc les infos sont perdues. Voici les trois étapes (recherche->script recherche->formulaire->script)et leur code respectif


    Formulaire_recherche_ajout.php
    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
    <?php
            
            session_start();
            
            if(isset($_SESSION['login_connexion']) && !empty($_SESSION['login_connexion']))
            {
                    
                    ?>
     
    		<html>
     
    			<head>
    				<title>Recherche</title>
    			</head>
     
    			<body>
     
    				<h3>Recherche d'une fiche</h3>
     
    				<form action="recherche_ajout.php" method="POST">
     
    					<table>
     
    						<tr>
     
    							<td>Nom : </td>
    							<td><input type="text" name="nom_recherche_ajout"/></td>
     
    						</tr>
     
    						<tr>
     
    							<td>Pr&eacute;nom : </td>
    							<td><input type="text" name="prenom_recherche_ajout"/></td>
     
    						</tr>
     
    						<tr>
     
    							<td>Date de naissance : </td>
    							<td>
     
    								<select name="jour_naissance_recherche_ajout">
     
    									<?php
                                                                                    
                                                                                    for($j=1; $j<32; $j++)
                                                                                    {
                                                                                            echo("<option value=\"$j\">$j</option>");
                                                                                    }
                                                                                    
                                                                            ?>
     
    								</select>
    								/
    								<select name="mois_naissance_recherche_ajout">
     
    									<?php
                                                                                    
                                                                                    for($m=1; $m<13; $m++)
                                                                                    {
                                                                                            echo("<option value=\"$m\">$m</option>");
                                                                                    }
                                                                                    
                                                                            ?>
     
    								</select>
    								/
    								<select name="annee_naissance_recherche_ajout">
     
    									<?php
                                                                                    
                                                                                    for($a=1944; $a<1995; $a++)
                                                                                    {
                                                                                            echo("<option value=\"$a\">$a</option>");
                                                                                    }
                                                                                    
                                                                            ?>
     
    								</select>
     
    							</td>
     
    						</tr>
     
    					</table>
     
    					<a href="../index.php">Retour</a>
    					<input type="reset"/>
    					<input type="submit" value="Rechercher"/>
     
    				</form>
     
    			</body>
     
    		</html>
     
    		<?php
                    
            }
            else
            {
                    header("Location: ../index.php");
            }
            
    ?>
    Script recherche
    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
    <?php
            
            session_start();
            
            if(isset($_SESSION['login_connexion']) && !empty($_SESSION['login_connexion']))
            {
                    
                    ?>
     
    		<html>
     
    			<head>
    				<title>R&eacute;sultat de la recherche</title>
    			</head>
     
    			<body>
     
    				<?php
     
    					if(isset($_POST["nom_recherche_ajout"]) == FALSE)
    					{
    						echo("Erreur dans le transfert du nom, veuillez recommancer svp");
    					}
    					else if (isset($_POST["prenom_recherche_ajout"]) == FALSE )
    					{
    						echo("Erreur dans le transfert du pr&eacute;nom, veuillez recommancer svp");
    					}
    					else if(empty($_POST["nom_recherche_ajout"]) == TRUE)
    					{
    						echo("Veuillez renseigner le nom de la personne<br/><br/><a href=\"formulaire_recherche_ajout.php\">Retour au formulaire de recherche</a>");
    					}
    					else if(empty($_POST["prenom_recherche_ajout"]) == TRUE )
    					{
    						echo("Veuillez renseigner le pr&eacute;nom de la personne<br/><br/><a href=\"formulaire_recherche_ajout.php\">Retour au formulaire de recherche</a>");
    					}
    					else
    					{
    						$nom_recherche_ajout = $_POST["nom_recherche_ajout"];
    						$prenom_recherche_ajout = $_POST["prenom_recherche_ajout"];
    						$jour_naissance_recherche_ajout = $_POST["jour_naissance_recherche_ajout"];
    						$mois_naissance_recherche_ajout = $_POST["mois_naissance_recherche_ajout"];
    						$annee_naissance_recherche_ajout = $_POST["annee_naissance_recherche_ajout"];
     
    						if ((is_numeric($nom_recherche_ajout) == FALSE) && (is_numeric($prenom_recherche_ajout) == FALSE))
    						{					
     
    							$Id = mysql_connect("localhost", "root", "");
     
    							mysql_select_db("suiviautorisation", $Id);
     
    							$ReqSQL = "	SELECT *
    										FROM personne
    										WHERE nom_personne='".$nom_recherche_ajout."'
    										AND prenom_personne='".$prenom_recherche_ajout."'
    										AND jour_naissance_personne='".$jour_naissance_recherche_ajout."'
    										AND mois_naissance_personne='".$mois_naissance_recherche_ajout."'
    										AND annee_naissance_personne='".$annee_naissance_recherche_ajout."'
    									";
     
    							$Res = mysql_query($ReqSQL, $Id);
    							$Nb = mysql_num_rows($Res);
     
    							if ( $Nb == 0 )
    							{
    								echo("Aucun r&eacute;sultat ne correspond &agrave; votre recherche<br/><br/><a href=\"formulaire_recherche_ajout.php\">Retour au formulaire de recherche</a>");
    							}
    							else
    							{
    								echo("Il y a ".$Nb." r&eacute;sultats correspondant &agrave; votre recherche<br/>");
     
    								for ( $Num = 1 ; $Num <= $Nb ; $Num = ( $Num + 1 ) )
    								{
    									$Ligne = mysql_fetch_array($Res);
     
    									$id_personne = $Ligne["id_personne"];
     
    									echo("
    											<table>
    												<tr><td>Nom : ".$Ligne["nom_personne"]."</td></tr>
    												<tr><td>Pr&eacute;nom : ".$Ligne["prenom_personne"]."</td></tr>
    												<tr><td>Date de naissance : ".$Ligne["jour_naissance_personne"]." / ".$Ligne["mois_naissance_personne"]." / ".$Ligne["annee_naissance_personne"]."</td></tr>
    												<tr>
    													<td><form action=\"formulaire_ajout_habilitation_personne.php\" method=\"POST\">
    															<input type=\"submit\" value=\"Ajouter une habilitation\"/>
    															<input type=\"hidden\" name=\"id_personne\" value=\"".$id_personne."\"/>
    														</form>
    													</td>
    												</tr>
    											</table><br/>
    										");
    								}
     
    								echo("<br/><a href=\"formulaire_recherche_ajout.php\">Retour au formulaire de recherche</a>");
     
    							}
     
    							mysql_free_result($Res);
     
    							mysql_close();
     
    						}
    						else
    						{
    							echo("Certains champs ont &eacute;t&eacute; mal renseign&eacute;s<br/><br/><a href=\"formulaire_recherche_ajout.php\">Retour au formulaire de recherche</a>");
    						}
     
    					}
     
    				?>
     
    			</body>
     
    		</html>
     
    		<?php
                    
            }
            else
            {
                    header("Location: ../index.php");
            }
            
    ?>
    Formulaire_ajout_habilitation_personne.php
    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&eacute;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&eacute;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&eacute;cification : 
     
    							<select name="specification_formation_1">
     
    								<option value="-1" selected="selected">-- Choisir une sp&eacute;cification --</option>
     
    							</select>
     
    							<br/>
     
    							Sp&eacute;cification : 
     
    							<select name="specification_formation_2">
     
    								<option value="-1" selected="selected">-- Choisir une sp&eacute;cification --</option>
     
    							</select>
     
    							<br/>
     
    							Sp&eacute;cification : 
     
    							<select name="specification_formation_3">
     
    								<option value="-1" selected="selected">-- Choisir une sp&eacute;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&eacute;e de validit&eacute; ( en ann&eacute;es ) : </td>
    								<td><input type="text" name="validite_formation"/></td>
     
    							</tr>
     
    							<tr>
     
    								<td>Fin de validit&eacute; : </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 &eacute;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&eacute;t&eacute; : </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&eacute;connexion</a>
     
    				</form>
     
    			</body>
     
    		</html>
     
    		<?php
                    
            }
            else
            {
                    header("Location: ../index.php");
            }
            
    ?>
    ajout_habilitation.php
    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
    <?php
            
            session_start();
            
            if(isset($_SESSION['login_connexion']) && !empty($_SESSION['login_connexion']))
            {
                    
                    ?>
     
    		<html>
     
    			<head>
    				<title>Ajout d'habilitation</title>
    			</head>
     
    			<body>
     
    				<?php
     
    					if(	isset($_POST["type_formation"]) == FALSE || 
    						isset($_POST["niveau_formation"]) == FALSE || 
    						isset($_POST["specification_formation_1"]) == FALSE || 
    						isset($_POST["specification_formation_2"]) == FALSE || 
    						isset($_POST["specification_formation_3"]) == FALSE || 
    						isset($_POST["jour_formation"]) == FALSE || 
    						isset($_POST["mois_formation"]) == FALSE || 
    						isset($_POST["annee_formation"]) == FALSE || 
    						isset($_POST["validite_formation"]) == FALSE || 
    						isset($_POST["lieu_formation"]) == FALSE || 
    						isset($_POST["organisme_evaluateur_formation"]) == FALSE ||
    						isset($_POST["nom_societe"]) == FALSE || 
    						isset($_POST["nom_employeur_societe"]) == FALSE)
    					{
    						echo("
    								Attention : Les informations n'ont pas &eacute;t&eacute; transmises.<br/>
    								<br/><a href=\"formulaire_ajout_habilitation_personne.php\">Retour au formulaire d'inscription</a>
    							");
    						exit;
    					}
    					else
    					{
    						if ((is_numeric($_POST["lieu_formation"]) == FALSE) ||
    							(is_numeric($_POST["nom_employeur_societe"]) == FALSE) && 
    							(is_numeric($_POST["validite_formation"]) == TRUE))
    						{	
    							$id_personne = $_POST["id_personne"];
    							$type_formation = $_POST["type_formation"];
    							$niveau_formation = $_POST["niveau_formation"];
    							$specification_formation_1 = $_POST["specification_formation_1"];
    							$specification_formation_2 = $_POST["specification_formation_2"];
    							$specification_formation_3 = $_POST["specification_formation_3"];
    							$jour_formation = $_POST["jour_formation"];
    							$mois_formation = $_POST["mois_formation"];
    							$annee_formation = $_POST["annee_formation"];
    							$validite_formation = $_POST["validite_formation"];
    							$jour_validite_formation = $jour_formation;
    							$mois_validite_formation = $mois_formation;
    							$annee_validite_formation = $annee_formation + $validite_formation;
    							$lieu_formation = $_POST["lieu_formation"];
    							$organisme_evaluateur_formation = $_POST["organisme_evaluateur_formation"];
    							$nom_societe = $_POST["nom_societe"];
    							$nom_employeur_societe = $_POST["nom_employeur_societe"];
     
    							$Id_type = mysql_connect("localhost", "root", "");
     
    								mysql_select_db("suiviautorisation", $Id_type);
     
    								$ReqSQL_type = "	
    													SELECT *
    													FROM type_formation_menu
    													WHERE id_type_formation_menu='".$type_formation."'
    												";
     
    								$Res_type = mysql_query($ReqSQL_type, $Id_type) or die ("pb : ".mysql_error()."<br/>");
    								$Nb_type = mysql_num_rows($Res_type);
     
    								if(($niveau_formation<=0)&&($specification_formation_1<=0)&&($specification_formation_2<=0)&&($specification_formation_3<=0))
    								{
    									$niveau_formation = " ";
    									$specification_formation_1 = " ";
    									$specification_formation_2 = " ";
    									$specification_formation_3 = " ";
    								}
    								else
    								{
    									if($Nb_type == 0)
    									{
    										$type_formation = $type_formation;
    									}
    									else
    									{
    										$Ligne = mysql_fetch_array($Res_type);
    										$type_formation = $Ligne["type_formation_menu"];
    									}
    								}
     
    							mysql_close();
     
    							$Id = mysql_connect("localhost", "root", "");
     
    								mysql_select_db("suiviautorisation");
     
    								$ReqSQLInsertion = "INSERT INTO `formation`(`id_personne`,
    																			`type_formation`,
    																			`niveau_formation`,
    																			`specification_formation_1`,
    																			`specification_formation_2`,
    																			`specification_formation_3`,
    																			`jour_formation`,
    																			`mois_formation`,
    																			`annee_formation`,
    																			`validite_formation`,
    																			`jour_validite_formation`,
    																			`mois_validite_formation`,
    																			`annee_validite_formation`,
    																			`lieu_formation`,
    																			`organisme_evaluateur_formation`,
    																			`nom_societe`,
    																			`nom_employeur_societe`)
    															VALUES ('$id_personne',
    																	'$type_formation',
    																	'$niveau_formation',
    																	'$specification_formation_1',
    																	'$specification_formation_2',
    																	'$specification_formation_3',
    																	'$jour_formation',
    																	'$mois_formation',
    																	'$annee_formation',
    																	'$validite_formation',
    																	'$jour_validite_formation',
    																	'$mois_validite_formation',
    																	'$annee_validite_formation',
    																	'$lieu_formation',
    																	'$organisme_evaluateur_formation',
    																	'$nom_societe',
    																	'$nom_employeur_societe')" ;
     
    								$Res = mysql_query($ReqSQLInsertion) or die("erreur : ".mysql_error());
     
    								if ($Res == true)
    								{
    									echo("Ok, l'ajout d'habilitation a &eacute;t&eacute; effectu&eacute;<br/><a href=\"formulaire_recherche_ajout.php\">Retour</a>");
    								}
    								else
    								{
    									echo("Attention : La tentative d'ajout a &eacute;chou&eacute;e<br/><a href=\"formulaire_recherche_ajout.php\">Retour</a>");
    								}
     
    							mysql_close () ;
    						}
    						else
    						{
    							echo("Certains champs ont &eacute;t&eacute; mal renseign&eacute;s<br/><br/><br/><a href=\"formulaire_ajout_habilitation_personne.php\">Retour au formulaire</a>");
    						}
    					}
    				?>
     
    			</body>
     
    		</html>
     
    		<?php
                    
            }
            else
            {
                    header("Location: ../index.php");
            }
            
    ?>
    Voila tout mon sac de noeuds

  5. #5
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Salut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    function confirmer(id_type_formation)
    					{if(id_type_formation<=0)
    						{
    							alert('Attention : Vous devez choisir le type de formation');
    return false;
    						}
    else return true;}

  6. #6
    Membre Expert
    Inscrit en
    Septembre 2002
    Messages
    2 307
    Détails du profil
    Informations forums :
    Inscription : Septembre 2002
    Messages : 2 307
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    function confirmer(id_type_formation)
    {
    if(id_type_formation<=0)
    {
    alert('Attention : Vous devez choisir le type de formation');
    return false;
    }
    return true;
    }
    ...
    <input type="submit" value="Enregistrer" onclick="return confirmer('<?php $a; ?>')"/>
    Edit : suis un peu lent ce matin! mais j'ai ajouter un retun dans le onclick!

  7. #7
    Membre averti
    Femme Profil pro
    ...
    Inscrit en
    Avril 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : ...

    Informations forums :
    Inscription : Avril 2009
    Messages : 49
    Par défaut
    Merci beaucoup ça fonctionne

  8. #8
    Membre Expert
    Inscrit en
    Septembre 2002
    Messages
    2 307
    Détails du profil
    Informations forums :
    Inscription : Septembre 2002
    Messages : 2 307
    Par défaut
    Citation Envoyé par titinesaku Voir le message
    Malheureusement j'ai dejà testé cette solution : ne fonctionne pas
    il manque un appel ajax là!
    '<?php $a; ?>'
    un peu tiré par les cheveux ton code...

  9. #9
    Membre averti
    Femme Profil pro
    ...
    Inscrit en
    Avril 2009
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : ...

    Informations forums :
    Inscription : Avril 2009
    Messages : 49
    Par défaut
    Nan c'est bon ça fonctionne merci beaucoup

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. test alert sur soumission de form
    Par Invité dans le forum jQuery
    Réponses: 4
    Dernier message: 17/02/2011, 12h01
  2. soumission de form serialise et input type file
    Par SpaceFrog dans le forum jQuery
    Réponses: 3
    Dernier message: 02/07/2010, 16h08
  3. soumission de form (mini tutoriel)
    Par sscouby dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 17/07/2008, 19h36
  4. [Forms V6] Alert Box
    Par plv69 dans le forum Oracle
    Réponses: 4
    Dernier message: 25/01/2006, 11h16
  5. [FORMS] alerte box
    Par chand_bing dans le forum Forms
    Réponses: 3
    Dernier message: 29/07/2004, 14h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo