Bonsoir
Que manque-t-il au code suivant pour que l'on reste sur la page du formulaire "formulaire.php", tant que celui-ci n'est pas rempli ?
Pourquoi ce code, au lieu de prendre en compte la condition préliminaire, ouvre-t-il tout de suite "reponse.php"?
Quelqu'un peut-il m'aider ?
formulaire.php
reponse.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 <?php if (!empty($_POST)) { extract($_POST); $valid = true; if (empty($nom)) { $valid=false; $erreur_nom='Vous devez inscrire votre nom!'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>RESTER SUR LE FORMULAIRE OU ENVOYER LA REPONSE</title> </head> <body> <h3>Formulaire</h3> <form name="devis" method="POST" action="reponse.php"> Saisissez votre nom <input type="text" name="nom" /> <input type="submit" name="valider" value="Réponse"> </form> </body> </html>
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>RESTER SUR LE FORMULAIRE OU ENVOYER LA REPONSE</title> </head> <body> <h3>Réponse</h3> <?php if (isset($_POST['valider'])) { $nom = $_POST['nom']; echo 'Salut '.$nom.'!'; } ?> </body> </html>
Partager