info:exemple_formulaire

Formulaire / form / forms exemple

Je suis un spécialiste des formulaires, base de l'interaction homme-machine, mais pour être honnête, depuis 2007 je les fais surtout avec des outils dédiés, principalement limesurvey, car je suis un flemmard.

Formulaire intelligent avec arrays

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0.1//EN">
<!-- $Id Exp $ -->
<!--Generated by quanta Plus template - freely use and distribute-->
<html>
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="GENERATOR" content="Eclipse">
  <link>
  <style type="text/css">
  table {
  border: solid 1px;
  }
  </style>
  <script>
  function imprimer() {
  	window.print();
  }
  </script>
</head>
 
<?php
###### array variables to modify
$arr = array(0, 1, 2, 3);
$liste = array("lait", "sucre", "sel", "anchois en boîte");
$quantites = array("1l", "1 kg", "500 g", "2 boîtes de 25g");
 
###### cgi

 
 
$check=$_POST['soumettre'];
if($check){
	echo "<body onload=\"imprimer()\">";
 
#echo "<br>passed variables check: " .$check ."<br>"; //tests
echo "<h1>Liste de commissions</h1><table>";
$j=0;
foreach ($arr as $i => $value) {
	$lavariable="var" .$j;
 
		$lavariable= $_POST[$lavariable];
		if($lavariable=="on") {
			#echo $lavariable ."<br>"; //tests
			echo "<tr><td>" .$liste[$j] ."</td><td>" .$quantites[$j] ."</td></tr>";
 
		}
	$j++;
 
}
echo "</table>
<h2><a href=\"form_commissions.php\">Retour</a></h2>
</body>
</html>";
exit;
}
###### else print form

?><body>
 
<form method="POST" action="">
<h1>Cliquez sur les produits à avoir puis sur le bouton "imprimez"</h1>
<table>
  <?php
 
#echo "liste des variables<hr>"; //tests

$j=0;
foreach ($arr as $i => $value) {
echo "<tr><td><input type=\"checkbox\" name=\"var" .$value ."\" id=\"var" .$value ."\">&nbsp;" .$liste[$j] ."</td><td>" .$quantites[$j] ."</td></tr>";
$j++;
}
?>
<tr><td><input type="reset" value="recommencer"></td><td><input type="submit" value="imprimer" name="soumettre"></td></tr>
</table>
</form>
<?
 ?>
</body>
</html>

source: http://www.commentcamarche.net/contents/html/htmlform.php3

<FORM method=post action="cgi-bin/script.pl">
Enregistrement d'un utilisateur
<TABLE BORDER=0>
<TR>
	<TD>Nom</TD>
	<TD>
	<INPUT type=text name="nom">
	</TD>
</TR>
 
<TR>
	<TD>Prénom</TD>
	<TD>
	<INPUT type=text name="prenom">
	</TD>
</TR>
 
<TR>
	<TD>Sexe</TD>
	<TD>
	Homme : <INPUT type=radio name="sexe" value="M">
	<br>Femme : <INPUT type=radio name="sexe" value="F">
	</TD>
</TR>
 
<TR>
	<TD>Fonction</TD>
	<TD>
	<SELECT name="fonction">
		<OPTION VALUE="enseignant">Enseignant</OPTION>
		<OPTION VALUE="etudiant">Etudiant</OPTION>
		<OPTION VALUE="ingenieur">Ingénieur</OPTION>
		<OPTION VALUE="retraite">Retraité</OPTION>
		<OPTION VALUE="autre">Autre</OPTION>
	</SELECT>
	</TD>
</TR>
<TR>
	<TD>Commentaires</TD>
	<TD>
	<TEXTAREA rows="3" name="commentaires">
	Tapez ici vos commentaires</TEXTAREA>
	</TD>
</TR>
 
<TR>
	<TD COLSPAN=2>
	<INPUT type="submit" value="Envoyer">
	</TD>
</TR>
</TABLE>
I have a bike:
<input type="checkbox" name="vehicle" value="Bike">
<br>
I have a car: 
<input type="checkbox" name="vehicle" value="Car">
<br>
I have an airplane: 
<input type="checkbox" name="vehicle" value="Airplane">
 
</FORM>
  • info/exemple_formulaire.txt
  • Dernière modification : 2020/12/10 08:51
  • de radeff