Formulaire Perl/Cgi

From Tuxunix
Jump to: navigation, search

Exemple


  • Methode Get

Code


   1.#!/usr/bin/perl
   2.     
   3.# entree standard dans la variable $in
   4.$in = $ENV{"QUERY_STRING"};
   5.       
   6.@champs = split(/&/,$in);
   7.       
   8.foreach $_ (@champs) {
   9.    ($nom, $valeur) = split(/=/,$_);
  10.    $champs{$nom}=$valeur;
  11.}
  12.       
  13.print("Content-Type: text/html\n\n");
  14.# puis le document HTML
  15.print <<"SORTIE";
  16.    <4/element/head.html">HEAD><4/element/title.html">TITLE> Reponse </4/element/title.html">TITLE></4/element/head.html">HEAD>
  17.    <4/element/body.html">BODY>
  18.    <4/element/h2.html">H2 ALIGN=CENTER>Reponse au questionnaire</4/element/h2.html">H2>
  19.    <4/element/center.html">CENTER><4/element/table.html">TABLE BORDER><4/element/tr.html">TR> <4/element/th.html">TH>Nom du champ <4/element/th.html">TH>Valeur</4/element/tr.html">TR>
  20.SORTIE
  21.       
  22.while (($nom, $valeur) = each(%champs)) {
  23.    print "<4/element/tr.html">TR>
  24.    <4/element/td.html">Td>$nom </4/element/td.html">td>
  25.    <4/element/td.html">Td>$valeur</4/element/td.html">td>
  26.    </4/element/tr.html">TR>";
  27.}
  28.print "</4/element/table.html">TABLE></4/element/center.html">CENTER></4/element/body.html">BODY>";


  • Formulaire PERL/CGI methode Post:

Exemple


  • Methode Post

Code


   1.#!/usr/bin/perl
   2.      
   3.read(STDIN, $in, $ENV{CONTENT_LENGTH});
   4.       
   5.@champs = split(/&/,$in);
   6.       
   7.       
   8.foreach $_ (@champs) {
   9.    ($nom, $valeur) = split(/=/,$_);
  10.    $champs{$nom}=$valeur;
  11.}
  12.       
  13.print("Content-Type: text/html\n\n");
  14.# puis le document HTML
  15.print <<"SORTIE";
  16.     <HEAD><TITLE> Reponse </TITLE></HEAD>
  17.     <BODY>
  18.     <H2 ALIGN=CENTER>Reponse au questionnaire</H2>
  19.     <CENTER><TABLE BORDER><TR> <TH>Nom du champ <TH>Valeur</TR>
  20.SORTIE
  21.       
  22.while (($nom, $valeur) = each(%champs)) {
  23.    print "<tr>
  24.        <td>$nom </td>
  25.        <td>$valeur</td>
  26.        </tr>";
  27.}
  28.print "</TABLE></CENTER></BODY>";