PHP: Exemple de traitement d’un menu de sélection du formulaire HTML

Author:

 formulaire
Download

<html>
<body>
<?php
if (isset($_POST ['etatenvoi']) == "oui")
{
  if (count ( $_POST ['fruits'] ) != 0)
  {
    echo "Votre sélection:";
  }
  else
  {
    echo "Vous n'avez rien sélectionné.
 
";
  }
  for($i = 0; $i < count ( $_POST ['fruits'] ); $i ++)
  {
    echo $_POST ['fruits'] [$i] . "";
  }
  ?><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Sélectionner d'autre?</a><?php
}
// Si le champs 'hidden' est null, Afficher le formulaire
if (isset($_POST ['etatenvoi'])!= "oui") {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="etatenvoi" value="oui" /> Faites vos choix: 
<select name="fruits[]" multiple="multiple">
<option value="Orange">orange</option>
<option value="pomme">pomme</option>
<option value="banane">Oranges</option>
<option value="fraise">fraise</option>
</select>
 
 
<input type="submit" value="Envoyer" /></form>
 
<?php
}
?>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *


two + 5 =