Bonjour,
Dans mon formulaire multi pages, pour la page saisie adresse livraison, l'utilisateur a la possibilité de remplir plusieurs adresses de livraison à partir de la même page qui se réaffiche en boucle en fait.
J'ai créée un tableau pour enregistrer les valeurs adresse session dans un tableau. Je dois créer un compteur qui incrémente les variables rentrées pour qu'en fin de traitement je puisse tout enregistrer dans la base mais je galère complètement.
Je n'arrive même plus à afficher mes variables déjà rentrées dans les input...
Est-ce que vous pouvez jeter un petit coup d'oeil s'il vous plait ?

Merci beaucoup


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
 
 <?php
 session_start(); 
 
if (isset($_POST['id'])) 
{
    $_SESSION['id_prospect'] = $_POST['id'];
}
 
if (isset($_POST['titre'])) {
    $_SESSION['adresse']['titre'] = $_POST['titre'];}
if (isset($_POST['prenom'])) {
    $_SESSION['adresse']['prenom'] = $_POST['prenom'];}
if (isset($_POST['nom'])) {
    $_SESSION['adresse']['nom'] = $_POST['nom'];}
if (isset($_POST['email'])) {
    $_SESSION['adresse']['email'] = $_POST['email'];}
 
 
//valeurs champs premier formulaire = inscription2.php	 
if (isset($_POST['labs'])) {
    $_SESSION['adresse2']['labs'] = $_POST['labs'];}
if (isset($_POST['company'])) {
    $_SESSION['adresse2']['company'] = $_POST['company'];}
if (isset($_POST['adress'])) {
    $_SESSION['adresse2']['adress'] = $_POST['adress'];}
if (isset($_POST['bat'])) {
    $_SESSION['adresse2']['bat'] = $_POST['bat'];}
if (isset($_POST['code_postal'])) {
    $_SESSION['adresse2']['code_postal'] = $_POST['code_postal'];}
if (isset($_POST['ville'])) {
    $_SESSION['adresse2']['ville'] = $_POST['ville'];}
if (isset($_POST['pays'])) {
    $_SESSION['adresse2']['pays'] = $_POST['pays'];}
if (isset($_POST['tel'])) {
    $_SESSION['adresse2']['tel'] = $_POST['tel'];}
if (isset($_POST['fax'])) {
    $_SESSION['adresse2']['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"].="Must be filled <br/>";
       $error_exist= true;
   } 
 
   // test sur company
   $company_ko= (strlen($company) < 2);
   if($company_ko) {
       $erreurs["company"]["msg"].="Must be filled <br/>";
       $error_exist= true;
   } 
 
   // test sur adress
   $adress_ko= (strlen($adress) < 2);
   if($adress_ko) {
       $erreurs["adress"]["msg"].="Must be filled <br/>";
       $error_exist= true;
   } 
 
   // test sur bat
   $bat_ko= (strlen($bat) < 2);
   if($bat_ko) {
       $erreurs["bat"]["msg"].="Must be filled<br/>";
       $error_exist= true;
   } 
 
   // test sur code postal
   $code_postal_ko= (strlen($code_postal) < 2);
   if($code_postal_ko) {
       $erreurs["code_postal"]["msg"].="Must be filled <br/>";
       $error_exist= true;
   } 
 
   // test sur city
   $ville_ko= (strlen($ville) < 2);
   if($ville_ko) {
       $erreurs["ville"]["msg"].="Must be filled <br/>";
       $error_exist= true;
   } 
 
 
 
   // test sur tel
   if(!is_numeric($tel)) {
      $erreurs["tel"]["msg"].= "Must contain only figures <br/>";
   }
 
   // test sur fax
   if(!is_numeric($fax)) {
      $erreurs["fax"]["msg"].= "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'; 
      } 
     } 
 
	 //----------------------------------------------------------------------------------------------------------------------------------
 
	 //ICI CONDITION POUR POUVOIR ENREGISTRER LES AUTRES ADRESSES facturation DANS VARIABLES DE SESSION
 
 
	 $_SESSION['adresse2'] = array();
	/* Subdivision de l'adresse facturation */
	$_SESSION['adresse2'][] = $labs;
	$_SESSION['adresse2'][]=  $company;
	$_SESSION['adresse2'][]= $adress;
	$_SESSION['adresse2'][]= $bat;
	$_SESSION['adresse2'][]= $code_postal;
	$_SESSION['adresse2'][] = $ville;
	$_SESSION['adresse2'][]= $pays;
	$_SESSION['adresse2'][] = $tel;  
	$_SESSION['adresse2'][]= $fax;
 
 
	if(isset($_POST['Other'])) {
	$nb_index=sizeof($_SESSION['adresse2']);
 
	//par une boucle on les parcours en affichant leur valeur
	for($i=0;$i<$nb_index;$i++){
 
	{
		echo $nb_index[$i].""; // on affiche l'élément du tableau avec l'index $i
	} 
 
		foreach($_SESSION['adresse2'] as $valeur)
		{
			echo "$valeur";
		} 
 
 
		}
 
	}
 
 
	//afficher contenu du tableau, à enlever en fin de test
	echo '<pre>';
	print_r($_SESSION['adresse2']);
	echo '</pre>';
 
 
?>
 
 
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
 
</head>
<body>
 
            <div id="contour_formulaire">
 
            <form name="facturation" action="inscriptionFacturation.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>
 
 
        <p class="TitreFormulaire1">Billing adress  #1<br/>              
	      <span class="ClickHere">Does my billing adress different from this one ?</span> <br/>              
		</p>
 
        <table width="740" border="0" cellpadding="0" cellspacing="0" >
          <tr>
            <td width="118"><label for="labs" class="TexteLogin">Dept/Labs : </label></td>
            <td width="282"><input name="labsn" type="text" class="loginRemplissage" SIZE="45" value="<?php echo $_SESSION['adresse2']['labs'][$i];?>"/>
            <span class="error">*</span></td>
            <td width="340" colspan="3" class="error2"><?php echo $erreurs["labs"]["msg"]; ?> </td>
          </tr>
          <tr>
            <td width="118"><label for="company" class="TexteLogin">Company : </label></td>
            <td width="282"><input name="company" type="text" class="loginRemplissage" SIZE="45" value="<?php if (!empty($_SESSION['adresse2']['company'])) echo htmlentities(trim($_SESSION['adresse2']['company'])); ?>"/>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> <?php echo $erreurs["company"]["msg"]; ?></td>
          </tr>
          <tr>
            <td width="118"><label for="adress" class="TexteLogin">Adress  : </label></td>
            <td><input name="adress" type="text" class="loginRemplissage" SIZE="45" value="<?php if (!empty($_SESSION['adresse2']['adress'])) echo htmlentities(trim($_SESSION['adresse2']['adress'])); ?>"/>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> <?php echo $erreurs["adress"]["msg"]; ?> </td>
          </tr>
          <tr>
            <td width="118"><label for="bat" class="TexteLogin">Building  : </label></td>
            <td width="282"><input name="bat" type="text" class="loginRemplissage" SIZE="45" value="<?php if (!empty($_SESSION['adresse2']['bat'])) echo htmlentities(trim($_SESSION['adresse2']['bat'])); ?>"/>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> <?php echo $erreurs["bat"]["msg"]; ?> </td>
          </tr>
          <tr>
            <td width="118"><label for="code_postal" class="TexteLogin">Zip code  : </label></td>
            <td width="282"><input name="code_postal" type="text" class="loginRemplissage" SIZE="20" value="<?php if (!empty($_SESSION['adresse2']['code_postal'])) echo htmlentities(trim($_SESSION['adresse2']['code_postal'])); ?>"/>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> <?php echo $erreurs["code_postal"]["msg"]; ?> </td>
          </tr>
          <tr>
            <td width="118"><label for="ville" class="TexteLogin">City  : </label></td>
            <td width="282"><input name="ville" type="text" class="loginRemplissage" SIZE="45" value="<?php if (!empty($_SESSION['adresse2']['ville'])) echo htmlentities(trim($_SESSION['adresse2']['ville'])); ?>"/>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> <?php echo $erreurs["ville"]["msg"]; ?> </td>
          </tr>
          <tr>
            <td width="118"><label for="pays" class="TexteLogin">Country  : </label></td>
            <td width="282">
			<select class="loginRemplissage" style="width:130px;" name="pays" id="pays" size="1">
 
 <option  value="Algeria"<?php if($_SESSION['adresse22']['pays'] == 'Algeria') echo "selected"; ?>>Algeria</option>
<option value="USA"<?php if($_SESSION['adresse2']['pays'] == 'USA') echo "selected" ;?>>USA</option>
</select>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> </td>
          </tr>
          <tr>
            <td width="118"><label for="tel" class="TexteLogin">Tel  : </label></td>
            <td width="282"><input name="tel" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['adresse2']['tel'])) echo htmlentities(trim($_SESSION['adresse2']['tel'])); ?>"/>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> <?php echo $erreurs["tel"]["msg"]; ?> </td>
          </tr>
          <tr>
            <td width="118"><label for="fax" class="TexteLogin">Fax : </label></td>
            <td width="282"><input name="fax" type="text" class="loginRemplissage" SIZE="30" value="<?php if (!empty($_SESSION['adresse2']['fax'])) echo htmlentities(trim($_SESSION['adresse2']['fax'])); ?>"/>
            <span class="error">*</span></td>
            <td colspan="3" class="error2"> <?php echo $erreurs["fax"]["msg"]; ?> </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td colspan="7" class="TexteErreur"><?php if (isset($erreur2)) echo '<br />',$erreur2;  ?></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td colspan="7" class="TexteErreur">&nbsp;</td>
          </tr>
 
          <tr>
            <td>&nbsp;</td>
 
			<td colspan="7" class="texteCheckBoxT" valign="top">
            <input type="submit" name="Other" class="TexteFormulaireBleuDessous2" value="Other" />&nbsp;&nbsp;I have other accounts from wich I can buy. </td>
          </tr>
 
		  <tr>
		    <td>&nbsp;</td>
		    <td colspan="7" class="TexteCheck">&nbsp;</td>
	      </tr>
		  <tr>
            <td>&nbsp;</td>
            <td colspan="7" class="error">* Must be mandatory filled </td>
          </tr>
		  <tr>
		    <td>&nbsp;</td>
		    <td colspan="7" class="TexteCheck">&nbsp;</td>
	      </tr>
		  <tr>
		    <td colspan="8"><table width="737" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="86" 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 width="114" class="loginRemplissage2"><div align="center"><strong><img src="images/Fleche.jpg" alt="" width="16" height="16" align="left" class="AlignementFleche5"/><a href="InterfineChemicals.php" class="loginRemplissage2Copie">Field of interest </a></strong> </div></td>
                <td width="273">&nbsp;</td>
                <td width="39">&nbsp;</td>
                <td width="109">&nbsp;</td>
 
                <td width="116"><input type="submit" name="inscription" class="AlignementNext" value=""/></td>
              </tr>
            </table></td>
	      </tr>
		  <tr>
		    <td>&nbsp;</td>
		    <td colspan="7" class="TexteCheck">&nbsp;</td>
	      </tr>
 
 
		  </td>
	      </tr>
        </table>
		</fieldset>     
              </form><br/>
		   </div>
 
 
</body>
</html>