amoussa11

Validate Form Data With PHP

Feb 16th, 2019
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1.  
  2. < ! DOCTYPE HTML >  
  3. < html >
  4. < head >
  5. < / head >
  6. < body >  
  7.  
  8. <? Php
  9. // définir des variables et définir des valeurs vides
  10. $ name = $ email = $ genre = $ comment = $ website = "" ;
  11.  
  12. if ( $ _SERVER [ "REQUEST_METHOD" ] == "POST" ) {
  13.   $ name = test_input ( $ _POST [ "name" ]);
  14.   $ email = test_input ( $ _POST [ "email" ]);
  15. ]);
  16.   $ comment = test_input ( $ _POST [ "comment" ]);
  17.   $ gender = test_input ( $ _POST [ "gender" ]);
  18. }
  19.  
  20. function test_input ($ data) {
  21.   $ data = trim ($ data);
  22.   $ data = stripslashes ($ data);
  23.   $ data = htmlspecialchars ($ data);
  24.   retourne $ data;
  25. }
  26. ?>
  27.  
  28. < h2 > Exemple de validation de formulaire PHP < / h2 >
  29. < form method = "post" action = " <? php echo htmlspecialchars ( $ _SERVER [ " PHP_SELF "]); ?> " >  
  30.   Nom:<entréetype =" text » nom = "nom" >
  31.   <br><br>
  32.   E-mail:<entréetype = "" texte nom = "email" >
  33.   <br><br>
  34.   Site Web:<entréetype = "text" nom = "site" >
  35.   <br><br>
  36.   Commentaire:<rangs = "5" cols = "40" > < / textarea >
  37.   < br > < br >
  38.   Sexe:
  39.    < entrée de type = "radio" nom = "sexe" valeur = "femelle" > Femelle
  40.    < entrée de type = "radio" nom = "genre" valeur = "homme" > homme
  41.    < type d' entrée = "radio" name = "sexe" valeur = "autre"> Autre
  42.    < br > <br >
  43.   < input type = "submit" name = "submit" value = "Submit" >  
  44. < / form >
  45.  
  46. <? php
  47. echo "<h2> Votre entrée: </ h2>" ;
  48. echo $ name;
  49. echo "<br>" ;
  50. echo $ email;
  51. echo "<br>" ;
  52. echo $ website;
  53. echo "<br>" ;
  54. echo $ comment;
  55. echo "<br>" ;
  56. echo $ genre;
  57. ?>
  58.  
  59. <
Advertisement
Add Comment
Please, Sign In to add comment