Le formulaire ci-dessous permet de mettre en oeuvre certains éléments à l'image des champs de saisie, d'une liste de choix de cases à cocher ainsi que de boutons.
Le formulaire permet de soumettre des informations fournies par le client, de plus, il contrôle également la validité des données transmises. Ainsi, un champs de saisie attendant des chiffres ne doit être composé que d'unbe valeur numérique sous peine de voir apparaître un message d'erreur, c'est le cas, notamment, du code postal.
Exemple [voir]<html> <body> <% Function Validation(Val_Champs, Type_Champs) Dim Champs_Valide Champs_Valide = True Select Case LCase(Type_Champs) Case "sexe" If Len(Val_Champs) = 0 Then Champs_Valide = False Case "nom" If Len(Val_Champs) = 0 Then Champs_Valide = False Case "prénom" If Len(Val_Champs) = 0 Then Champs_Valide = False Case "situation" If Len(Val_Champs) = 0 Then Champs_Valide = False Case "email" If Len(Val_Champs) < 5 Or _ Instr(1, Val_Champs, " ") <> 0 Or _ InStr(1, Val_Champs, "@") < 2 Or _ (InStrRev(Val_Champs, ".") < InStr(1, Val_Champs, "@") + 2) _ Then Champs_Valide = False End If Case "adresse" If Len(Val_Champs) = 0 Then Champs_Valide = False Case "cp" If Len(Val_Champs) <> 5 Or Not IsNumeric(Val_Champs) Then Champs_Valide = False End If Case "ville" If Len(Val_Champs) = 0 Then Champs_Valide = False Case "pays" If Len(Val_Champs) < 2 Then Champs_Valide = False Case "commentaire" If Len(Val_Champs) = 0 Then Champs_Valide = False End Select Validation = Champs_Valide End Function Sub Affiche_Champs(Txt_Champs, index) %> <tr> <td align="right"><b><%= Txt_Champs %> : </b></td> <td> <input name="<%= Txt_Champs %>" type="text" value="<%= Request.Form(Txt_Champs) %>" tabindex="index"> </td> <td> <% If champs_Errone(LCase(Txt_Champs)) Then Response.Write "<img src=""../../images/interface/erreur.gif""" _ & " border=""0"" width=""20"" height=""20"" alt=""Erreur !"">" End If %> </td> </tr> <% End Sub Sub Affiche_Bouton() %> <input type="submit" value="Soumettre" name="soumission"> <input type="reset" value="Annuler" name="annulatiuon"> <% End Sub Dim Champs Dim champs_Errone Set champs_Errone = Server.CreateObject("Scripting.Dictionary") For Each Champs in Request.Form If Validation(Request.Form(Champs), Champs) = False Then champs_Errone.Add LCase(Champs), True End If Next If Request.Form.Count <> 0 And champs_Errone.Count = 0 Then %> <form action="" method="post"> <h2>Vous allez soumettre ces informations :</h2> <% For Each Champs In Request.Form Response.Write Champs & " : <b>" & Request.Form(Champs) _ & "</b><br>" Next Affiche_Bouton %> </form> <% Else If Request.Form.Count <> 0 Then %> <h2 style="color: #FF0000"> Des erreurs ont été détectées ! </h2> <p> Veuillez modifier les champs de saisie repérés par un icône. </p> <% End If %> <form action="formulaire.asp" method="post" name="formulaire"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td> <input type="radio" name="sexe" value="Mr" CHECKED tabindex="1">Monsieur<br> <input type="radio" name="sexe" value="Mme">Madame<br> <input type="radio" name="sexe" value="Mlle">Mademoiselle </td> </tr> <tr> <td> <% Affiche_Champs "Nom", 2 Affiche_Champs "Prénom", 3 %> </td> </tr> <tr> <td><b>Situation :</b></td> <td> <select name="situation" size="1" tabindex="4"> <option value="Célibataire" CHECKED> Célibataire </option> <option value="Marié(e)"> Marié(e) </option> <option value="Concubinage"> Concubinage </option> <option value="Pacs"> Pacs </option> <option value="Veuf(ve)"> Veuf(ve) </option> <option value="Divorcé(e)"> Divorcé(e) </option> </select> </td> </tr> <tr> <td> <% Affiche_Champs "Email", 5 Affiche_Champs "Adresse", 6 Affiche_Champs "CP", 7 Affiche_Champs "Ville", 8 Affiche_Champs "Pays", 9 %> </td> </tr> <tr> <td colspan="2" align="right"> <textarea name="commentaire" cols="23" rows="3" tabindex="10"> Commentaire... </textarea> </td> </tr> <tr> <td colspan="2" align="center"> <% Affiche_Bouton %> </td> </tr> </table> </form> <% End If %> </body> </html> |