• Publicidad

No entiendo nada. Problema en Formulario

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

No entiendo nada. Problema en Formulario

Notapor Gabs » 2005-11-16 22:42 @988

Hola, casi no conozco Perl, el único contacto que he tenido es con los formularios que se envían a una cuenta de email, ahora estoy hecha bolas y espero alguien me pueda ayudar.

Tengo un formulario que tiene varios campos, pero el PL únicamente me envía 3 campos, nombre, email y comentarios. No sé cómo editar el PL para que me lea y envíe los datos de los demás campos.

Los campos que necesito con los siguientes:
Nombre -*
email -*
Empresa- no lo manda
actividad- no lo manda
tel - no lo manda
ciudad - no lo manda
comentarios - *


Voy a poner acá el PL: (disculpen, creo que está un poco largo):
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. # Poner el archivo .pl en CGI-BIN para poder ejecutarlo
  4. # junto con la librería cgi-lib.pl
  5.  
  6. require "cgi-lib.pl";
  7. print "Content-type: text/html\n\n";
  8. &ReadParse;
  9.  
  10. $nombre   = $in{'Nombre'};
  11. $email   = $in{'email'};
  12. $Empresa   = $in{'Empresa'};
  13. $actividad   = $in{'activ'};
  14. $telefono = $in{'tel'};
  15. $ciudad   = $in{'ciudad'};
  16. $coment   = $in{'comentarios'};
  17.  
  18. #Crear el mensaje con los datos de la Forma
  19.  
  20. $now = localtime time;
  21.  
  22. $mensaje = $now . "\n\n";
  23. $mensaje = $mensaje . "Nombre     : " . $nombre . "\r\n";
  24. $mensaje = $mensaje . "Telefono   : " . $telefono . "\r\n";
  25. $mensaje = $mensaje . "Comentarios: \r\n";
  26. $mensaje = $mensaje . "-----------------------------------------------------\r\n";
  27. $mensaje = $mensaje . $coment . "\r\n";
  28. $mensaje = $mensaje . "-----------------------------------------------------\r\n";
  29. $mensaje = $mensaje . "remitente\r\n";
  30.  
  31. #Get user,pass,server or use defaults.
  32.  
  33. $user    = "email\@usuario.com";     # No usar la de webmaster por seguridad
  34. $pass    = "password";
  35. $server  = "direccion ip";                        # smtp.dominio.com (no cambiar)
  36. $from    = "mail from:<email\@usuario.com>";
  37. $to      = "To: DESTINATARIO";                    # Heder, Nombre del Destinatario
  38. $rcpt    = "RCPT TO:<email\@usuario.com>";     # Puede ser una de yahoo etc.
  39. $subject = "Subject: Comentarios";
  40. $data    = "data";
  41. $fin     = ".";
  42.  
  43. #This is a simple method to communicate with the server.
  44. use Socket; #I used this rather than Net::SMTP to make the example more clear
  45.  
  46. #Encrypt the user and pass
  47. $user = encode_base64($user); #Yes the encryption for AUTH is really this easy
  48. $pass = encode_base64($pass); #Base 64 is not really and encryption just a translation
  49.                               #But it works!
  50.  
  51. chomp($user);   #Get rid of line ending
  52. chomp($pass);   #Get rid of line ending
  53.  
  54. #open a socket and begin cummunication with the server
  55.    
  56.     socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')); #set up the socket
  57.     connect(SOCK, sockaddr_in(25, inet_aton($server)));        #connect to my server on port 25
  58.     sysread(SOCK, $Response, 1024);                            #Read what the server says
  59.     send(SOCK, "ehlo dominio.com\r\n", 0);                      #Hello my name is ....
  60.  
  61.  
  62.     #Tell the server we wish to use Authentication
  63.     send(SOCK, "AUTH LOGIN\r\n",0); #Ask for AUTH Login
  64.  
  65.     #the Response you see now is
  66.     #334 VXNlcm5hbWU6
  67.     #The stuff at the end is just Username: encoded in base64
  68.    
  69.     #Send the encrypted username
  70.     send(SOCK, $user . "\r\n", 0); #Encrypted User Name
  71.  
  72.     #The response you see now is
  73.     #334 UGFzc3dvcmQ6
  74.     #The stuff at the end is just Password: encoded in base64
  75.  
  76.     #send the encrypted password
  77.     send(SOCK, $pass . "\r\n", 0); #Encrypted Pass
  78.  
  79.     #You will not get the Response
  80.     #235 go ahead
  81.  
  82.     #A failure will return
  83.     #535 auth failure
  84.    
  85.     #you are now loged in and could send a message to anyone you please.
  86.     #I left out the command to send mail so that I do not get thousands
  87.     #of messages, but I think the commands to send mail to SMTP via Sockets
  88.     #is pretty well covered
  89.  
  90.     send(SOCK, $from . "\r\n", 0);
  91.     sysread(SOCK, $Response, 1024);
  92.                
  93.     send(SOCK, $rcpt . "\r\n", 0);
  94.     sysread(SOCK, $Response, 1024);
  95.  
  96.     send(SOCK, $data . "\r\n", 0);
  97.     sysread(SOCK, $Response, 1024);
  98.  
  99.     send(SOCK, $to . "\r\n", 0);
  100.     sysread(SOCK, $Response, 1024);
  101.  
  102.     send(SOCK, $subject . "\r\n", 0);
  103.     sysread(SOCK, $Response, 1024);
  104.  
  105.     send(SOCK, $mensaje . "\r\n", 0);
  106.     sysread(SOCK, $Response, 1024);
  107.  
  108.     send(SOCK, $fin . "\r\n", 0);
  109.     sysread(SOCK, $Response, 5424);
  110.    
  111.     close(SOCK);
  112. if ( $Response =~ m/250 Message received/ )
  113. {
  114. print "<html>
  115. </head>
  116. <body>
  117. <p align=\"center\"><b><font size=\"3\">El mensaje fue enviado con Exito!</font></b></p>
  118. <p align=\"center\"><b>Gracias!</b></p>
  119. <p>&nbsp;</p>
  120. <p>&nbsp;</p>
  121. </body>
  122. </html>";
  123. }
  124. else
  125. {
  126. print "<html>
  127. </head>
  128. <body>
  129. <p align=\"center\"><b><font size=\"3\">El mensaje No pudo ser  enviado !</font></b></p>
  130. <p align=\"center\"><b>Failed to Connect</b></p>
  131. <p>&nbsp;</p>
  132. <p>&nbsp;</p>
  133. </body>
  134. </html>";
  135. }
  136.  
  137.     #This is a base 64 subroutine taken from planet source code.
  138.     #It is pretty standard. stuff.
  139.  
  140. sub encode_base64
  141. {
  142.     my $res = "";
  143.     my $eol = $_[1];
  144.     $eol = "\n" unless defined $eol;
  145.     pos($_[0]) = 0;                          # ensure start at the beginning
  146.     while ($_[0] =~ /(.{1,45})/gs) {
  147.         $res .= substr(pack('u', $1), 1);
  148.         chop($res);
  149.     }
  150.     $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
  151.     # fix padding at the end
  152.     my $padding = (3 - length($_[0]) % 3) % 3;
  153.     $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
  154.     # break encoded string into lines of no more than 76 characters each
  155.     if (length $eol) {
  156.        $res =~ s/(.{1,76})/$1$eol/g;
  157.     }
  158.  
  159.     $res;
  160. }
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4

¿Alguien me puede indicar cómo debo agregar el código para los otros campos?

:wink:
Gabs
Perlero nuevo
Perlero nuevo
 
Mensajes: 3
Registrado: 2005-11-16 22:27 @977

Publicidad

Notapor explorer39 » 2005-11-17 05:48 @283

¿Has editado la página web donde está el formulario y colocado en él esos mismos campos editables (cajas de texto) con esos mismos nombres?
explorer39
 

Acerca de CGI

Notapor Gabs » 2005-11-17 09:59 @458

Hola, gracias por tu respuesta...

La página web donde está el formulario, sí la edité integrándole los campos con los mismos nombres... pero aunque los llenes al momento de procesar el formulario, no envía esos campos, únicamente se mandan:
*nombre
*email
*comentarios


¿Cómo se pueden agregar en el PL?
Gabs
Perlero nuevo
Perlero nuevo
 
Mensajes: 3
Registrado: 2005-11-16 22:27 @977

Notapor explorer39 » 2005-11-17 11:18 @512

  1. Comprueba que los campos editables están dentro de la etiqueta <form> dentro del HTML y que tienen el atributo 'name' puesto a el mismo nombre que los campos que esperas
  2. Revisa el código dentro de la subrutina ReadParse para comprobar que saca todos los parámetros enviados por el usuario y no sólo los que tres que sí funcionan.
explorer39
 

Notapor Gabs » 2005-11-17 17:45 @781

¡Hola de nuevo!

Ya quedó resuelto el problema...

Resulta que los campos que tenía en el HTML también los debía agregar al PL, de la misma forma que aparecían los otros:
$empresa = $in{'empresa'};
$actividad = $in{'actividad'};
$ciudad = $in{'ciudad'};


Y además los campos en la forma debían tener mismo nombre (mayúsculas y minúsculas) que las variables citadas en el PL...

Tan simple para los expertos y gran conflicto para los super principiantes.

Gracias a explorer39 por tus respuestas y a RafaReta-Mcgyver por tu valiosa ayuda en enseñarme cómo integrar otros campos en un PL.

¡Nos vemos! :)
Gabs
Perlero nuevo
Perlero nuevo
 
Mensajes: 3
Registrado: 2005-11-16 22:27 @977

Notapor Perl user » 2005-11-19 15:15 @677

Te pudiste haber ahorrado muchos problemas usando Email::Simple + Email::Send, ya que estás violando varios de los atributos especificados en el RFC2822 que especifican la formación correcta de un mensaje y sus encabezados.

Saludos.
Marco A. Manzo
[email protected]
http://www.unixmonkeys.com/amnesiac/
Perl Programming Language
Perl user
Maestro honorario
Maestro honorario
 
Mensajes: 271
Registrado: 2004-11-03 21:11 @924


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 32 invitados

cron