Hello Mark,

Thursday, August 09, 2001, Mark Ross <[EMAIL PROTECTED]> wrote:

MR> I'm curious how I can condense this code. I'm pulling
MR> my values from a Web submitted form (using CGI), and I
MR> need to untaint them.

MR> But, each form field has different requirement for
MR> what characters it can match (account number should
MR> only be numbers, etc).

MR> I was wondering if there's a better way to do go
MR> through these all without dupicating so much code? I'd
MR> be more than willing to give up the customized error
MR> messages if I could reduce these down to oneliners.
there are more than one way...

my %check = (
name_first => {
                regex => '^(\w[\w ]*)$',
                err   => "<p>The <strong>First Name field</strong> was either blank or 
contained illegal characters. Please go back and re-enter it.</p>"
              },
name_last  => {
                regex => '^(\w[\w ]*)$',
                err   => "<p>The <strong>First Name field</strong> was either blank or 
contained illegal characters. Please go back and re-enter it.</p>"
              },
account    => {
                regex => '^(\d*)$',
                err   => "<p>The Account field was either blank or contained illegal 
characters (it must contain only digits). Please go back and re-enter it</p>"
              }
);

foreach my $i (keys %check)
{
  my $prm = param( $i );
  my $tst = $check{$i}{regex};
  if ( (defined($prm) and ($prm =~ /$tst/) ) )
  {
    $submission{$i} = $1;
  }
  else
  {
    $submission{$i} = "";
    $message       .= $check{$i}{err};
  }
}

Best wishes,
 Maxim                            mailto:[EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to