hux has asked for the wisdom of the Perl Monks concerning the following question:

Hiya Perl Monks.

Would one of you most helpful people be able to provide me with a snippet of code that can perform the following:

1. Take input from a web form and place it into variables
2. Validate the variables

I have read in other posts that there are secure and insecure ways of performing this. I need it to be locked down as much as possible as it it going to be running on a public-facing server. I read something about a -T option or something on the #!/usr/bin/perl command.
With regards to validation, i just need it to check one of the variables to make sure it only contains characters/numbers and no symbols

Cheers

Replies are listed 'Best First'.
•Re: Need help with simple form input
by merlyn (Sage) on Aug 23, 2002 at 22:59 UTC
    There are plenty of snippets in perldoc CGI and perldoc perlsec. Try reading those first, and asking questions based on what you've read. If you've already read those, then try reading some more advanced materials, like my columns.

    -- Randal L. Schwartz, Perl hacker

Re: Need help with simple form input
by Popcorn Dave (Abbot) on Aug 23, 2002 at 23:13 UTC
    Merlyn has a good point there. There are tons of sites with sample code. You might look at the Big Nose Bird web site. They've got a lot of stuff like that and it's geared more towards the beginner.

    Good luck!

    Some people fall from grace. I prefer a running start...

      Why go there when you can get everything you need right here? All you have to do is Super Search for it!
Re: Need help with simple form input
by Cody Pendant (Prior) on Aug 24, 2002 at 09:02 UTC
    If you really need a quick and dirty version, you can just use this:
    use CGI; CGI::ReadParse();
    now all your form field inputs are in a hash called "%in".

    The keys are the form field names. If you've got a field called "username", it's in $in{'username'} -- I know people will frown on this because it's not the correct way to go, not object-oriented, but hell, it's quick, isn't it?

    Now all you have to do is a regular expression. if($in{'username'} !~ m/a-z0-9/) and you're done.

    Watch out for multiple values from checkboxes or duplicate-name fields though.
    --

    ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;