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

PHP & Base de données Discussion :

Récupérer sélection dans liste déroulante pays


Sujet :

PHP & Base de données

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Points : 52
    Points
    52
    Par défaut Récupérer sélection dans liste déroulante pays
    Bonjour à tous,

    J'ai une liste déroulante avec quelques pays que j'ai géré de cette façon pour que le pays choisi reste sélectionné le temps de la session et du passage sur les autres pages du formulaire. J'ai des erreurs notice, je ne sais pas bien comment gérer l'affichage. Est-ce que vous pouvez m'aider ?
    merci d'avance

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <select class="loginRemplissage" style="width:130px;" name="pays" id="pays" size="1">
     
     <option  value="France"<?php if($_SESSION['forma']['pays'] == 'France') echo "selected"; ?>>France</option>
    <option value="Espagne"<?php if($_SESSION['forma']['pays'] == 'Espagne') echo "selected" ; ?>>Espagne</option>
    <option value="Italie"<?php if($_SESSION['forma']['pays'] == 'Italie') echo "selected" ; ?>>Italie</option>
    <option value="Royaume-Uni"<?php if($_SESSION['forma']['pays'] == 'Royaume-Uni') echo "selected" ; ?>>Royaume-Uni</option>
    <option value="Canada"<?php if($_SESSION['forma']['pays'] == 'Canada') echo "selected" ; ?>>Canada</option>
    <option value="Etats-Unis"<?php if($_SESSION['forma']['pays'] == 'Etats-Unis') echo "selected" ; ?>>Italie</option>
    <option value="Chine"<?php if($_SESSION['forma']['pays'] == 'Chine') echo "selected" ;?>>Chine</option>
    <option value="Japon"<?php if($_SESSION['forma']['pays'] == 'Japon') echo "selected" ;?>>Japon</option>
     
    </select>

  2. #2
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2011
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2011
    Messages : 21
    Points : 22
    Points
    22
    Par défaut
    Salut,

    tu as vérifié que ta variable $_SESSION['forma']['pays'] est bien initialisée ?

  3. #3
    Membre du Club
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Points : 52
    Points
    52
    Par défaut
    Bonjour Kzou7,
    En fait j'ai mis ça en début de code pour initialiser les variables de mon formulaire :

    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
     
    //valeurs champs premier formulaire = inscription2.php	 
    if (isset($_POST['labs'])) {
        $_SESSION['forma']['labs'] = $_POST['labs'];}
    if (isset($_POST['company'])) {
        $_SESSION['forma']['company'] = $_POST['company'];}
    if (isset($_POST['adress'])) {
        $_SESSION['forma']['adress'] = $_POST['adress'];}
    if (isset($_POST['bat'])) {
        $_SESSION['forma']['bat'] = $_POST['bat'];}
    if (isset($_POST['code_postal'])) {
        $_SESSION['forma']['code_postal'] = $_POST['code_postal'];}
    if (isset($_POST['ville'])) {
        $_SESSION['forma']['ville'] = $_POST['ville'];}
    if (isset($_POST['pays'])) {
        $_SESSION['forma']['pays'] = $_POST['pays'];}
    if (isset($_POST['tel'])) {
        $_SESSION['forma']['tel'] = $_POST['tel'];}
    if (isset($_POST['fax'])) {
        $_SESSION['forma']['fax'] = $_POST['fax'];}

  4. #4
    Membre du Club
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Points : 52
    Points
    52
    Par défaut
    Voilà le code complet de ma page si ça peut aider.
    Merci

    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
     
    <?php
     session_start(); // En premier dans la page 
     
    //valeurs champs premier formulaire = inscription1.php
    if (isset($_POST['titre'])) {
        $_SESSION['form0']['titre'] = $_POST['titre'];}
    if (isset($_POST['prenom'])) {
        $_SESSION['form0']['prenom'] = $_POST['prenom'];}
    if (isset($_POST['nom'])) {
        $_SESSION['form0']['nom'] = $_POST['nom'];}
    if (isset($_POST['email'])) {
        $_SESSION['form0']['email'] = $_POST['email'];}
     
    //valeurs champs premier formulaire = inscription2.php	 
    if (isset($_POST['labs'])) {
        $_SESSION['forma']['labs'] = $_POST['labs'];}
    if (isset($_POST['company'])) {
        $_SESSION['forma']['company'] = $_POST['company'];}
    if (isset($_POST['adress'])) {
        $_SESSION['forma']['adress'] = $_POST['adress'];}
    if (isset($_POST['bat'])) {
        $_SESSION['forma']['bat'] = $_POST['bat'];}
    if (isset($_POST['code_postal'])) {
        $_SESSION['forma']['code_postal'] = $_POST['code_postal'];}
    if (isset($_POST['ville'])) {
        $_SESSION['forma']['ville'] = $_POST['ville'];}
    if (isset($_POST['pays'])) {
        $_SESSION['forma']['pays'] = $_POST['pays'];}
    if (isset($_POST['tel'])) {
        $_SESSION['forma']['tel'] = $_POST['tel'];}
    if (isset($_POST['fax'])) {
        $_SESSION['forma']['fax'] = $_POST['fax'];}
     
     
    // on initialise le tableau des erreurs
    $erreurs= array(
       "labs" =>          array("msg" => ""),
       "company" =>       array("msg" => ""),
       "adress" =>        array("msg" => ""),
       "bat" =>           array("msg" => ""),
       "code_postal" =>   array("msg" => ""),
       "ville" =>         array("msg" => ""),
       "pays" =>          array("msg" => ""),
       "tel" =>           array("msg" => ""),
       "fax" =>           array("msg" => ""),
    );
     
    $select= ' selected="selected" ';
     
     
    $error_exist= false;
    $erreur2= "";
     
    $labs=        (isset($_POST['labs']))          ?($_POST['labs'])         :("");
    $company=     (isset($_POST['company']))       ?($_POST['company'])      :("");
    $adress=      (isset($_POST['adress']))        ?($_POST['adress'])       :("");
    $bat=         (isset($_POST['bat']))           ?($_POST['bat'])          :("");
    $code_postal= (isset($_POST['code_postal']))   ?($_POST['code_postal'])  :("");
    $ville=       (isset($_POST['ville']))         ?($_POST['ville'])        :("");
    $pays=        (isset($_POST['pays']))          ?($_POST['pays'])         :("");
    $tel=         (isset($_POST['tel']))           ?($_POST['tel'])          :("");
    $fax=         (isset($_POST['fax']))           ?($_POST['fax'])          :("");
     
     
     // on teste si le visiteur a soumis le formulaire
    if(isset($_POST['inscription'])) {
     
     //si tous les champs sont vides(verif avec empty), erreur2 = tous les champs sont requis
       if(empty($labs) || empty($company) || empty($adress) || empty($bat) || empty($code_postal) || empty($ville) || empty($pays) || empty($tel) || empty($fax)) {
          $erreur2 = "All fields are requested !"; 
          $error_exist= true;  
       }
     
       // test sur laboratoire
       $labs_ko= (strlen($labs) < 2);
       if($labs_ko) {
           $erreurs["labs"]["msg"].="Fill the field labs !<br/>";
           $error_exist= true;
       } 
     
       // test sur company
       $company_ko= (strlen($company) < 2);
       if($company_ko) {
           $erreurs["company"]["msg"].="Fill the field company !<br/>";
           $error_exist= true;
       } 
     
       // test sur adress
       $adress_ko= (strlen($adress) < 2);
       if($adress_ko) {
           $erreurs["adress"]["msg"].="Fill the field adress !<br/>";
           $error_exist= true;
       } 
     
       // test sur bat
       $bat_ko= (strlen($bat) < 2);
       if($bat_ko) {
           $erreurs["bat"]["msg"].="Fill the field building !<br/>";
           $error_exist= true;
       } 
     
       // test sur code postal
       $code_postal_ko= (strlen($code_postal) < 2);
       if($code_postal_ko) {
           $erreurs["code_postal"]["msg"].="Fill the field postal code !<br/>";
           $error_exist= true;
       } 
     
       // test sur city
       $ville_ko= (strlen($ville) < 2);
       if($ville_ko) {
           $erreurs["ville"]["msg"].="Fill the field city !<br/>";
           $error_exist= true;
       } 
     
     
       // test sur country
       $pays_ko= (strlen($pays) < 2);
       if($pays_ko) {
           $erreurs["pays"]["msg"].="Fill the field country !<br/>";
           $error_exist= true;
       } 
     
       // test sur tel
       if(!is_numeric($tel)) {
          $erreurs["tel"]["msg"].= "This fiels must contain only figures !<br/>";
       }
     
       // test sur fax
       if(!is_numeric($fax)) {
          $erreurs["fax"]["msg"].= "This fiels must contain only figures !<br/>";
       }
     
     
       if(!$error_exist) {
     
    	 	   // et on commence la session qui s'appelle email
             $_SESSION['email'] = $email; 
             header('Location: InterfineChemicals.php'); 
             exit(); 
       }
       else { 
             $erreur2 = 'One of the fields is empty !'; 
          } 
         } 
    ?>
     
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    </head>
    <body>
     
                <div id="contour_formulaire">
                <form name="forma" action="inscription2.php" method="POST">
    		<fieldset style="border-color:#73aad2;border-size:2px;" width="625">  
    		<legend class="titre_labelaut"> Four steps and few clicks...<span class="Style4"></span></legend>
     
            <img src="images/Ronds.jpg" alt="" width="250" height="57" align="right" class="AlignementPointFormul"/>
     
     
            <p class="TitreFormulaire1">Fill the form  : <br/>              
    		</p>
     
            <table width="628" border="0" cellpadding="0" cellspacing="0" >
      		<tr>
        	<td width="131"> <label for="labs" class="TexteLogin">Dept/Labs : </label></td>
    		<td width="192">
    		<input name="labs" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['labs'])) echo htmlentities(trim($_SESSION['forma']['labs'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["labs"]["msg"]; ?>  		</td>
      		</tr>
     
      		<tr>
        	<td width="131"> <label for="company" class="TexteLogin">Company : </label></td>
    		<td width="192">
    		<input name="company" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['company'])) echo htmlentities(trim($_SESSION['forma']['company'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["company"]["msg"]; ?></td>
      		</tr>
     
      		<tr>
        	<td width="131"> <label for="adress" class="TexteLogin">Adress  : </label></td>
    		<td>
    		<input name="adress" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['adress'])) echo htmlentities(trim($_SESSION['forma']['adress'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["adress"]["msg"]; ?> </td>
      		</tr>
     
     
    		  <tr>
        	<td width="131"> <label for="bat" class="TexteLogin">Building  : </label></td>
    		<td width="192">
    		<input name="bat" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['bat'])) echo htmlentities(trim($_SESSION['forma']['bat'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["bat"]["msg"]; ?> </td>
    		  </tr>
     
     
      		<tr>
        	<td width="131"> <label for="code_postal" class="TexteLogin">Postal code  : </label></td>
    		<td width="192">
    		<input name="code_postal" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['code_postal'])) echo htmlentities(trim($_SESSION['forma']['code_postal'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["code_postal"]["msg"]; ?> </td>
      		</tr>
     
     
    		  <tr>
        	<td width="131"> <label for="ville" class="TexteLogin">City  : </label></td>
    		<td width="192">
    		<input name="ville" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['ville'])) echo htmlentities(trim($_SESSION['forma']['ville'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["ville"]["msg"]; ?> </td>
    		  </tr>
     
     
    		  <tr>
        	<td width="131"> <label for="pays" class="TexteLogin">Country  : </label></td>
    		<td width="192">
     
    		<select class="loginRemplissage" style="width:130px;" name="pays" id="pays" size="1">
     
     <option  value="France"<?php if($_SESSION['forma']['pays'] == 'France') echo "selected"; ?>>France</option>
    <option value="Espagne"<?php if($_SESSION['forma']['pays'] == 'Espagne') echo "selected" ; ?>>Espagne</option>
    <option value="Italie"<?php if($_SESSION['forma']['pays'] == 'Italie') echo "selected" ; ?>>Italie</option>
    <option value="Royaume-Uni"<?php if($_SESSION['forma']['pays'] == 'Royaume-Uni') echo "selected" ; ?>>Royaume-Uni</option>
    <option value="Canada"<?php if($_SESSION['forma']['pays'] == 'Canada') echo "selected" ; ?>>Canada</option>
    <option value="Etats-Unis"<?php if($_SESSION['forma']['pays'] == 'Etats-Unis') echo "selected" ; ?>>Italie</option>
    <option value="Chine"<?php if($_SESSION['forma']['pays'] == 'Chine') echo "selected" ;?>>Chine</option>
    <option value="Japon"<?php if($_SESSION['forma']['pays'] == 'Japon') echo "selected" ;?>>Japon</option>
     
    </select>
     
     
    		<span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["pays"]["msg"]; ?>  </td>
    		  </tr>
     
     
    		  <tr>
        	<td width="131"> <label for="tel" class="TexteLogin">Tel  : </label></td>
    		<td width="192">
    		<input name="tel" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['tel'])) echo htmlentities(trim($_SESSION['forma']['tel'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["tel"]["msg"]; ?>  </td>
    		  </tr>
     
     
      		<tr>
        	<td width="131"> <label for="fax" class="TexteLogin">Fax : </label></td>
    		<td width="192">
    		<input name="fax" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['forma']['fax'])) echo htmlentities(trim($_SESSION['forma']['fax'])); ?>"/><span class="error">*</span>		</td>
      		<td colspan="6" class="error2"> <?php echo $erreurs["fax"]["msg"]; ?>  		</td>
      		</tr>
     
     
    		<tr>
      		<td>&nbsp;</td>
      		<td colspan="10" class="TexteErreur"><?php if (isset($erreur2)) echo '<br />',$erreur2;  ?></td>
    		</tr>
     
      		<tr>
      		  <td>&nbsp;</td>
      		  <td colspan="7" class="TexteCheck">* Must be mandatory filled </td>
      		  </tr>
      		<tr>
      		  <td height="28" colspan="2"><table width="144" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="80" class="loginRemplissage2"><div align="center"><strong><img src="images/Fleche.jpg" alt="" width="16" height="16" align="left" class="AlignementFleche5"/><a href="inscription1.php" class="loginRemplissage2Copie">Account</a></strong></div></td>	
                  <td>&nbsp;</td>
                </tr>
     
              </table></td>
      		  <td width="197"></td>
      		  <td width="4">&nbsp;</td>
      		  <td width="4">&nbsp;</td>
      		  <td width="4">&nbsp;</td>
      		  <td width="14">&nbsp;</td>
      		  <td width="82"><input type="submit" name="inscription" class="AlignementNext" value=""/></td>
      		</tr>
      		</table>
              </fieldset>     
                  </form><br/>
     
    		   </div>
     
     
    </body>
    </html>

  5. #5
    Membre averti Avatar de hariman
    Homme Profil pro
    Développeur Java, Android
    Inscrit en
    Janvier 2008
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations professionnelles :
    Activité : Développeur Java, Android
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2008
    Messages : 200
    Points : 413
    Points
    413
    Par défaut
    Bonjour,

    Je viens de tester ton code et je ne vois aucun erreur.

    Sinon, c'est quoi le message d'erreur ? (le message après "notice")
    Pour voir le message d'erreur en clair, regarde-le à partir du code-source de la page (dans le navigateur)

  6. #6
    Membre du Club
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Points : 52
    Points
    52
    Par défaut
    Bonjour Hariman et merci pour ton aide,

    Pour l'erreur notice, ça m'affiche ça :
    Notice: Undefined index: forma in C:\wamp\www\Test_AUTHENTIFICATION_25janvier2012 - Copie\inscription2.php on line 263

Discussions similaires

  1. Sélection dans liste déroulante
    Par Trebor_ dans le forum Langage
    Réponses: 1
    Dernier message: 15/03/2008, 20h02
  2. Réponses: 1
    Dernier message: 16/06/2007, 18h24
  3. pas de sélection dans liste déroulante (cantine)
    Par mystikgirl30 dans le forum IHM
    Réponses: 2
    Dernier message: 05/03/2007, 11h50
  4. Sélection dans liste déroulante (Access 2002)
    Par BizutAccess dans le forum Access
    Réponses: 5
    Dernier message: 19/12/2006, 12h41
  5. [SQL] récupérer sélection dans liste déroulante
    Par nerick dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 06/12/2005, 11h30

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