[Perl] formularios

César Cerda González cesacego@bital.com.mx
Wed, 10 Sep 2003 14:51:39 -0500


Puedes verificar donde estas colocando tu CGI,
si es apache con linux, por default la ubicación para los archivos 
ejecutables es: .

/var/www/cgi-bin/

si ubicas el archivo en el directorio para html :
"/var/www/html/" sucede lo que comentas.

John Robeto 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
>
>************************************************************************=
***********
>Este mensaje de correo se origino desde Internet  y su creador puede ser=
 o no 
>quien dice ser, ademas de que la  información contenida en el mensaje =
y 
>cualquier archivo adjunto, puede o no ser información exacta.
>
>
>This message originated from the Internet. It is originator may or may n=
ot be 
>who they claim to be and the information contained in the message and an=
y 
>attachments may or may not be  accurate.
>************************************************************************=
***********
>
>  
>


*********************************************************************************

La información contenida en este Correo electrónico es confidencial.
Puede también se privilegie legalmente. Si usted no es el destinatario usted no puede copiar, re-enviar, abrir o usar cualquier parte de él. Si usted ha recibido este mensaje por error, por favor borrelo asi como todas las copias de su sistema y notifique al remitente inmediatamente por el Correo electrónico. 
No puede garantizarse que las comunicaciones de Internet sean oportunas, seguras, libres de error o virus. 
El remitente no acepta obligación por cualquier error u omision que se generen como resultado. 

The information contained in this E-mail is confidential. It may
 also be legally privileged. If you are not the addressee you may  not
 copy, forward, disclose or use any part of it. If you have received
 this message in error, please delete it and all copies from your
 system and notify the sender immediately by return E-mail.

Internet communications cannot be guaranteed to be timely, secure,
error or virus-free. The sender does not accept liability for any
errors or omissions which arise as a result.

*********************************************************************************