Re: Using CGI.pm to set up textfields and then parse them

2009-01-07 Thread marys
On Jan 5, 8:33 pm, g...@lazymountain.com (Greg Jetter) wrote:
 On Monday 05 January 2009 2:22:08 pm marys wrote:





  Does anyone know how to set up a large number of textfields for data
  input and then parse them conveniently?  In the CGI.pm book it shows
  how to use the form element 'textfield' like so:

  #!/usr/bin/perl -wT
  use CGI::Carp qw(fatalsToBrowser);
  use CGI ':standard';
  use CGI::Pretty;
  use strict;
  use diagnostics;
  my $x = new CGI;
  print $x-header;
  print $x-start_html;
   print $x-center($x-br, $x-h1(Here are three textfields:\n),
  $x-startform(-method=POST,-action=parsnip.cgi),
  textfield(-name='X1',-size=5.),
  textfield(-name='X2',-size=5.),
  textfield(-name='X3',-size=5.),
  $x-p,
  $x-submit( -name=Submit));
  print $x-endform;
  print $x-end_html;

  and I would like to check that the fields contain no special
  characters:

  #!/usr/bin/perl -wT
  use CGI::Carp qw(fatalsToBrowser);
  use CGI qw(:standard -no_xhtml);
  #use CGI ':standard';
  use CGI::Pretty;
  use strict;
  use diagnostics;
  my $x = new CGI;

  my $X1=param('X1'); my $X2=param('X2'); my $X3=param('X3');
  if(
        ($X1 !~ /^[\d.]+$/)  ($X1 !~ /^\s*$/)

     || ($X2 !~ /^[\d.]+$/)  ($X2 !~ /^\s*$/)
     || ($X3 !~ /^[\d.]+$/)  ($X3 !~ /^\s*$/) )

  {
     print $x-header;
          print $x-start_html(-title='parsnip',-bgcolor='silver');
     print $x-font({color=blue});
          print $x-center( br, $x-h1(Error in input!\n),
          $x-h1( Use digits and decimal points only!\n),
          $x-h2( Exiting!\n) );
     exit;
  }else{
     print $x-redirect(-URL='done.cgi');
  }

  with the 'done.cgi' script:

  #!/usr/bin/perl -wT
  use CGI::Carp qw(fatalsToBrowser);
  use CGI qw(:standard -no_xhtml);
  #use CGI ':standard';
  use CGI::Pretty;
  use strict;
  use diagnostics;
  my $x = new CGI;

     print $x-header;
          print $x-start_html(-title='done',-bgcolor='silver');
     print $x-font({color=blue});
          print $x-center( br, $x-h1(Done!\n);
             exit;

  The problem is that if I want to collect data from lots of textfields,
  like maybe 100, I get huge, sloppy scripts where I have to do a lot of
  typing for the variables X1-X100 and I make a lot of mistakes.  I bet
  there's a better way in the Perl world to do this.  I tried making an
  array going from 1 to 100 and calling the variables X.$_ but it
  didn't work.
  Is there a better way that anyone knows about?  Thank you.

 use a template system like HTML::Template to create you form page , not  
 CGI.pm , and  process it with CGI.pm . Or use  HTML to create your form. if
 your text fields are static and  won't change. Something like this you want
 to separate out the  presentation of the form from the processing of the form
 input.

 Greg- Hide quoted text -

 - Show quoted text -

Thanks, Greg.  the HTML::Template looks like something that will work.
ms


--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: Send email using SMTP

2009-01-07 Thread Gunnar Hjalmarsson

Adam Jimerson wrote:

I solved my problem using the sendmail with the code below in my script:

open (MAIL, |/usr/sbin/sendmail -t );
print MAIL From: someaddr...@somedomain\n;
print MAIL To: someaddre...@somedomain\n;
print MAIL Content-Type: text/plain\n;
print MAIL Subject: Very simple email test\n\n;
print MAIL Body of the message;
close (MAIL);


This is kind of off topic, but are you using the -T switch on your script?  
When I tried to open /usr/bin/mail with that switch on I get a error 
message about an insecure environment command.


Did it just say insecure environment? On my box it says: Insecure 
$ENV{PATH} ..., which means that you need to untaint the $ENV{PATH} 
variable. The easiest way to do that is:


$ENV{PATH} = '';

Please read more about Perl security in perldoc perlsec.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Login code

2009-01-07 Thread Brent Clark

Hiya

Would anyone have any example code of sessions for logins.

I basically would like to create a logon (username and password entered) 
page and create sessions. Maybe

too time stamp the session and if time has expired then display like a
expired session page.

If anyone can help it would be appreciated

Kind Regards
Brent Clark


--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/