[Perl] Re: formularios

Mauricio Herrera Cuadra arareko@yahoo.com
Wed, 10 Sep 2003 17:45:57 -0700 (PDT)


Hola.
No revise tu script a fondo, pero lo primero que veo es que la ruta
especificada en la linea "shebang" hacia el interprete de Perl es
incorrecta:

#!/urs/bin/perl      (debe ser #!/usr/bin/perl)

Prueba corrigiendo eso.
Saludos :)

--- John Robeto <johnroberto2001@yahoo.es> wrote:
> Hola a todos, mi problema tiene que ver con CGI, es
> el
> siguiente:
> 
> Trabajo con un formulario y un script CGI en Perl
> bajo
> Apache. Si ejecuto el script directamente con
> Explorer
> funciona pero cuando envío el formulario me pide
> autorización para descargar el script (con la
> extensión .pl) o me muestra el contenido del scritp
> en
> texto plano (con la extensión .cgi). La idea es la
> típica, que un usuario cumplimente el formulario y
> que
> al enviarlo aparezca una página de agradecimiento al
> tiempo que la información llegue a mi cuenta de
> correo. Os envío tanto el formulario como el script,
> GRACIAS:
> 
> Ejercicio.htm
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
> Transitional//EN">
> <html>
> <head>formulario</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
> </head>
> 
> <body>
> <form name="formulario" method="post"
> action="ejercicio.cgi">
>   ERES<br>
>   <p>
>     <label>
>     <input type="radio" name="hombre"
> value="opción">
>     hombre</label>
>     <br>
>     <label>
>     <input type="radio" name="mujer" value="opción">
>     mujer</label>
>     <br>
>   </p>
>   <br>
>   Tus comentarios:<br>
>   <textarea name="comentarios"></textarea><br>
>   <p>Please <input type="submit" value="submit this
> form">
>      when finished or <input
>   type="reset" value="clear it"> to start over. </p>
> </form>
> </body>
> </html>
> 
> 
> ejercicio.cgi
> 
> 
> #!/urs/bin/perl
> 
> use CGI;
> $query = new CGI;
> print $query->header;
> 
>  %postInputs = readPostInput();
>  $dateCommand = "date";
>  $time = `$dateCommand`;
>  open (MAIL, "|/usr/sbin/sendmail -t") || return 0;
> 
>  select (MAIL);
>  print << "EOF";
>  To:   johnroberto2001\ @yahoo.es # esta es mi
> cuenta
> de correo separada con “\” del dominio
>  From: $postInputs{ 'Contact_Email'}
>  Subject: $postInputs{ 'Organization'}  Information
> Requested
> 
>  $time
>  $postInputs{ 'Organization'}  Information Requested
>  Name: $postInputs{ 'Contact_FullName'}
>  Email: $postInputs{ 'Contact_Email'}
>  Street Address: $postInputs{
> 'Contact_StreetAddress'}
>  Street Address (cont): $postInputs{
> 'Contact_Address2'}
>  City: $postInputs{ 'Contact_City'}
>  State : $postInputs{ 'Contact_State'}
>  Zip: $postInputs{ 'Contact_ZipCode'}
>  Work Phone: $postInputs{ 'Contact_WorkPhone'}
>  Home Phone: $postInputs{ 'Contact_HomePhone'}
>  FAX: $postInputs{ 'Contact_FAX'}
>  Email: $postInputs{ 'Contact_Email'}
>  Comments: $postInputs{ 'comments'}
> 
> 
>  EOF
>     close(MAIL);
>     select (STDOUT);
>     printThankYou();
> 
>  sub readPostInput(){
>     my (%searchField, $buffer, $pair, @pairs); #
> declaración de variables
>     if ($ENV{ 'REQUEST_METHOD'}  eq 'POST'){	# si el
> método cabecera del formulario es igual a post
>        read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH'}
> );
> # guarde con STDIN en $buffer el contenido de
> CONTENT_LENGHT
>        @pairs = split(/&/, $buffer); # separe los
> pares name=value&name=value en el array @pairs
>        foreach $pair (@pairs){
>           ($name, $value) = split(/=/, $pair);
> #separe
> los pares name=value en $name y $value
> respectivamente
>           $value =~ tr/+/ /; # sustituya (caracter
> por
> caracter, "tradusca") todo signo + por espacio
>           $value =~
> s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #
> la función pack convierte una lista de escalares a
> formato binario
>           $name =~ tr/+/ /;
>           $name =~
> s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1)) eg;
>           $searchField{ $name}  = $value; # crea un
> hash que almacena los datos de $name (clave) y
> $value
> (valor)
>        }
>     }
>     return (%searchField); # el hash creado se envia
> al programa
>  }
> 
>  sub printThankYou(){
>  print << "EOF";
>  Content-Type: text/html
> 
>  <HEAD>
>  <TITLE>THANK YOU FOR FOR YOUR REQUEST</TITLE>
>  </HEAD>
>  <BODY>
>  <TABLE CELLSPACING=2 CELLPADDING=2 border=0
> width=600>
>  <TR><th><BR>
>  <center>
>  <FONT SIZE=+3><B>Thank You name </b></font>
>  </center><BR><BR>
> 
>  <CENTER><B><FONT SIZE=+1>
>  <P>For submitting your information. We will get
> back
> with you shortly.
>  </P>
>  </FONT></B><CENTER>
>  </th>
>  </table>
>  </BODY>
>  </HTML>
> 
>  EOF
>  }
> 
> ___________________________________________________
> Yahoo! Messenger - Nueva versión GRATIS
> Super Webcam, voz, caritas animadas, y más...
> http://messenger.yahoo.es
> _______________________________________________
> Perl mailing list
> Perl@tlali.iztacala.unam.mx
> http://tlali.iztacala.unam.mx/mailman/listinfo/perl

=====
MAURICIO HERRERA CUADRA
arareko@yahoo.com
http://www.geocities.com/arareko/

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com