Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check_required not working?

Status
Not open for further replies.

lwinstead

IS-IT--Management
Feb 4, 2002
157
US
I'm using Matt's Formmail 1.92 script, and everything is working like it should, with the exception of the "check_requred" subroutine. It'll catch a required field if its blank, but not if its got a single space in it.

I can't make it work. Can anyone help me understand the logic behind this? Also, and maybe more importantly, can someone help me figure out what constitutes a "space" character in perl? Thanks!

<<<<[flux]>>>>
 
Okay, I figured it out. The logic behind the if statement was a little confusing. Specifically, we're talking about the portion of the check_required subroutine that checks for blank required fields or required fields containing a space.

First off, this only checks for ONE space in the field. If the field has more than ONE space, it'll break, and the check_required will pass.

Secondly, shouldn't there be some way to check for multiple spaces? I.E. Aren't spaces returned as empty characters?

Thirdly, I simply modified the IF statement to include another condition: "$Form{$require} eq ' ' || " This ensures that it'll check for one space in the field.

I say again, shouldn't spaces be recognized by the form as empty characters, such that just checking for a blank field would be good enough? Sheesh!

<<<<[flux]>>>>
 
It'll catch a required field if its blank, but not if its got a single space in it.

blank (as in nothing, not even a space) is different than a space. A space is a single character just like: X. And it's also because Matt Wright had much more enthusiasm than knowledge or skill when he wrote his infamous FormMail script, so it's not surprising the code doesn't do what his notes says it should do.

I say again, shouldn't spaces be recognized by the form as empty characters, such that just checking for a blank field would be good enough? Sheesh!

Spaces are not empty characters. There are a couple of ways to check if a field (or variable) is "blank", all though that is not technically the correct way to say it. You check if the field is "defined" or "true". If a field contains even a single space it is defined/true.

It will also help to post the code you are working with or just the relevant part of the code, not everyone has formmail.pl handy to look at.
 
KevinADC,

Thanks for the info. And thanks for the reminder about the code.

Nonetheless, I understand what you're saying about spaces not being empty characters. I also know that Perl should be able to ignore form fields that contain nothing but spaces when parsing the form. Maybe its time to look elsewhere than Matt's almighty form. Too many people have now told me that his hype is bigger than his byte...

The Code:
# If it is a regular form field which has not been filled
# in or filled in with a space, flag it as an error
# field.
elsif (!defined($Form{$require}) || $Form{$require} eq '') {
push(@error,$require);
}

Its that elsif statement that's got me confused. Doesn't it say "if the required field is not defined (blank), or if the required field equals [the empty set], then push an error"? Aren't those the same conditions??


<<<<[flux]>>>>
 
perl can ignore form fields that contain only spaces (or varibles that contain only spaces) but you have to tell it to.

Code:
if ($Form{$require} =~ /^\s*$/) {
  print 'This variable has only spaces so I will ignore it';
}

Doesn't it say "if the required field is not defined (blank), or if the required field equals [the empty set], then push an error"?

Yes, thats what it is saying more or less. But what it's not saying: "or if required field has only space(s) push an error". Which is in direct contradicton to what the note just before that code says: "or filled in with a space".

Matt has posted (somewhere) that he knows his code is not too well written, but since it is still used so much he has decided to just keep it available to the many people that still wish to use his old scripts. Here are much better scripts that are designed to replace Matts old scripts:

 
Kevin,

Okay, thanks for that snippet of code. I don't know Perl, really, but programming in general is just logical thinking to me, so when I grasp the grammar, its pretty straight forward from there.

As for the NMS program, I've already downloaded it, and have yet to implement it. I'm actually moving between webservers in-house, so this will be a good time to get the NMS program working.

Again, thanks for your help.

<<<<[flux]>>>>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top