Problème formulaire multi-page avec SESSION
Bonjour,
Je suis actuellement entrain de faire un formulaire depuis maintenant 1semaine et j'ai déjà fais ceci: ICI .
Comme vous pouvez le constater, ce formulaire fonctionne parfaitement bien, mais il s'agit d'un formulaire sur une et même page. Hors je souhaiterais le continuer, je souhaiterais qu'il s'étende sur 2autres pages + 1 page de récapitulatif avant l'envoi sur ma boite mail.
Je m'arrache les cheveux sur ce tuto: ICI
J'ai compris le grosso-modo du fonctionnement. J'ai essayé de faire un petit test à l'aide du tuto en re-créant un formulaire basique, sur 3pages.
Mais lors de l'uploid sur mon ftp voila se que cela donne: ICI
Voici le code dans l'ordre des pages .php :
Page1.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php
session_start(); // On démarre la session AVANT toute chose
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<title>Peexstudio | Page1</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form method="post" action="<?php echo CFG_FORM_ACTION; ?>?stage=<?php echo CFG_STAGE_ID+1; ?>">
<label for="nom">NOM :</label>
<input type="text" name="nom" value="<?php echo $_SESSION['forms'][CFG_STAGE_ID]['nom']; ?>" />
<br />
<label for="prenom">PRENOM :</label>
<input type="text" name="prenom" value="<?php echo $_SESSION['forms'][CFG_STAGE_ID]['prenom']; ?>" />
<br />
<input type="submit" value="continuer" />
</body>
</html> |
Page2.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php
session_start(); // On démarre la session AVANT toute chose
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<title>Peexstudio | Page2</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form method="post" action="<?php echo CFG_FORM_ACTION; ?>?stage=<?php echo CFG_STAGE_ID+1; ?>">
<label for="nom">EMAIL :</label>
<input type="text" name="email" value="<?php echo $_SESSION['forms'][CFG_STAGE_ID]['email']; ?>" />
<br />
<label for="prenom">VILLE :</label>
<input type="text" name="ville" value="<?php echo $_SESSION['forms'][CFG_STAGE_ID]['ville']; ?>" />
<br />
<input type="submit" value="continuer" />
</body>
</html> |
Page3.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?php
session_start(); // On démarre la session AVANT toute chose
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<title>Peexstudio | Page3</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form method="post" action="<?php echo CFG_FORM_ACTION; ?>?stage=<?php echo CFG_STAGE_ID+1; ?>">
<label for="message">MESSAGE :</label>
<textarea name="message" cols="15" rows="10"><?php echo $_SESSION['forms'][CFG_STAGE_ID]['message']; ?></textarea>
<input type="submit" value="continuer" />
</body>
</html> |
Resume.php :
Code:
1 2 3 4 5 6 7 8
| <?php
session_start();
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
?> |
et Index.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| session_start();
// Configuration du script
define('CFG_FORM_ACTION', basename(__FILE__)); // Cela permet de changer le nom du script d'index
$forms = array( // Voici la liste des formulaires, pratique pour mettre en place le menu de navigation
1 => 'page1',
2 => 'page2',
3 => 'page3'
);
// Récupération du numéro de l'étape en cours
if(empty($_GET['stage']) or !is_numeric($_GET['stage']))
{
define('CFG_STAGE_ID', 1);
}
else
{
// En situation réelle, il faudrait vérifier l'existence de cette page
define('CFG_STAGE_ID', intval($_GET['stage']));
}
// Déclaration de la variable de session
if(empty($_SESSION['forms']))
{
$_SESSION['forms'] = array();
}
// Affichage du menu en haut de la page
$items = array();
foreach($forms as $form_id => $form_name)
{
if(empty($_SESSION['forms'][$form_id]))
{
$items[] = $form_name;
}
else
{
$items[] = '<a href="'.basename(__FILE__).'?stage='.$form_id.'">'.$form_name.'</a>';
}
}
$items[] = '<a href="'.basename(__FILE__).'?stage=4">Résumé</a>';
echo implode(' - ', $items).'<br /><br />';
// Récupération des informations, affichage du formulaire
switch(CFG_STAGE_ID)
{
case 4:
// Récupération des informations du formulaire précédent
if(!empty($_POST))
{
if(!empty($_POST['message']))
{
$_SESSION['forms'][CFG_STAGE_ID-1] = array(
'message' => $_POST['message']
);
}
}
// Affichage du formulaire
require('http://peexstudio.fr/tests/resume.php');
break;
case 3:
// Valeurs par défaut
if(empty($_SESSION['forms'][CFG_STAGE_ID]))
{
$_SESSION['forms'][CFG_STAGE_ID] = array(
'message' => ''
);
}
// Récupération des informations du formulaire précédent
if(!empty($_POST))
{
if(!empty($_POST['email'])
and preg_match('/^([^@\s<&>]+)@(?:([-a-z0-9]+)\.)+([a-z]{2,})$/i', $_POST['email'])
and preg_match('#[a-zA-Z-ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ\s]#', $_POST['ville'])
{
$_SESSION['forms'][CFG_STAGE_ID-1] = array(
'email' => $_POST['email'],
'ville' => $_POST['ville'],
);
}
}
// Affichage du formulaire
require('http://peexstudio.fr/tests/page3.php');
break;
case 2:
// Valeurs par défaut
if(empty($_SESSION['forms'][CFG_STAGE_ID]))
{
$_SESSION['forms'][CFG_STAGE_ID] = array(
'nom' => '',
'prenom' => '',
);
}
// Récupération des informations du formulaire précédent
if(!empty($_POST))
{
if(!empty($_POST['nom'])
and preg_match('#[a-zA-Z-ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ\s]#', $_POST['nom'])
and preg_match('#[a-zA-Z-ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ\s]#', $_POST['prenom'])
{
$_SESSION['forms'][CFG_STAGE_ID-1] = array(
'nom' => $_POST['nom'],
'prenom' => md5($_POST['prenom']),
);
}
}
require('http://peexstudio.fr/tests/page2.php');
break;
case 1:
default:
// Valeurs par défaut
if(empty($_SESSION['forms'][CFG_STAGE_ID]))
{
$_SESSION['forms'][CFG_STAGE_ID] = array(
'nom' => '',
'prenom' => '',
);
}
require('http://peexstudio.fr/tests/page1.php');
break;
} |
Pourriez-vous me dire d'où vient le problème? je suis assez novice en la matière. Merci