Gossamer Forum
Home : General : Perl Programming :

form check

Quote Reply
form check
Hi,

I have a form in which I don't allow certain number variations to be inputed...so, basically if either of the two numbers below are entered, it will produce an error. It works fine right now the way I'm doing it below, but now, I need to add like 35-40 different number variations, and this probably isn't the best way to do it.

if (($FORM{'name'} eq "1234") or ($FORM{'name'} eq "5432")) {

Anyone know of better way to do this?

I tried this:

my @Number = (
'1234',
'5432',
);

Then within the sub:
if ($FORM{'Name'} eq '@Number')
{

But it doesn't work, and I'm probably missing something...any ideas or suggestions would be great. Thanks.

Quote Reply
Re: form check In reply to
Well, this probably isn't the most efficient way to handle things but it would make it easier to add number variations.
You could define a variable like

$denied = '1233 3242 234234 32423';

Then

@deniednums = split(/ /, $denied);
foreach $number(@deniednums) {
chomp($number);
if ($FORM{'name'} =~ /$number/i) {
&callsomething
}

That would match number combos that even contain the numbers that you specified in $denied 411233534 would match since it contains 1233 or you could just make it
if ($FORM{'name'} = "$number") {
which would find exact matches only.

Good Luck!

Quote Reply
Re: form check In reply to
Hmm, well this doesn't seem to be working. For some reason, anything placed into the form now is not being accepted?? I'm not sure why though, any ideas? Benny Hill--isn't that a show? That hasn't been on in years! Thanks for your help, appreciate it.

Quote Reply
Re: form check In reply to
Seems like this should work...
Code:
my @denied = qw(1 2 3 4);
foreach $num (@denied) {
if ($form{'name'} == $num) {
$denied = 1;
last;
}
}
if ($denied) {
&error;
} else {
&procede;
}
Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: form check In reply to
Unfortunately, still no luck with those codes either Drew. Still just returning the error page with anything that is inputed (it should only return an error if certain numbers are inputed). Not sure why it's not working, cause it looks right?? Oh well, thanks for the help though guys, I appreciate it.

Quote Reply
Re: form check In reply to
Code:
$FORM{'Name'} = 5432;

my @Number = (
1234,
5432,
);

if (grep {/$FORM{'Name'}/} @Number) {
print 'invalid number';
}
--mark

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: form check In reply to
Right on Mark! You the man....it works great. I was almost there... Thanks for everyone's help, I appreciate it.

Quote Reply
Re: form check In reply to
Ok, one more question. I'm tyring to exclude anything with certain numbers and it would probably cut down on the amount of number variations that I would need to input if I could get this to work. Ok, let's say I wish to have anything with the numbers 54 and 12 to be excluded. So if a user inputs 5431 or 1234 or 1231 or 5434, etc... it won't allow it. I'm not sure where to start with this yet, but do you think it would be to difficult to approach it this way? Thanks again.