Home: Perl Programming Help: Intermediate:
form data



jacksonpt
Deleted

Apr 7, 2000, 9:36 AM


Views: 2074
form data

I have put 2 perl scripts up intended to capture HTML form information. Sometimes the data is captured, and e-mailed to me correctly, sometimes it is not... and I can't figure out why. It seems like there are times when the data is not being captured at all (since I receive a blank e-mail). Does this sound like anything to you?

I could really use some help with this one.
Thanks,
Jackson

PS - my e-mail is jtaylor@binghamton.edu if you think this might get fairly involved. Thanks again.


darian
Deleted

Apr 7, 2000, 2:14 PM


Views: 2074
Re: form data

Are you checking to see if the user has entered any information? You can check a couple of ways. The first is using javascript. The second is to test each field as it is sent to the script.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if($field1 eq "") { print "You need to fill in this field."; }</pre><HR></BLOCKQUOTE>

Post your code so we can go through it and check.


jacksonpt
Deleted

Apr 12, 2000, 5:13 AM


Views: 2074
Re: form data

Thanks Darian. I work for a state university and it never occured to me that people may be submitting blank forms. I threw in some javascript to prevent them from doing so, and it seems to have helped.

If I run into any more problems, I will post the code. Thanks again.

-Jackson


Jasmine
Administrator

Apr 12, 2000, 7:53 AM


Views: 2074
Re: form data

What I do to prevent someone from entering a field full of spaces (which would make $field1 eq "" false is):

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


($temp = $field1) =~ s/ //g;
unless($temp){print "You need to fill in this field}
</pre><HR></BLOCKQUOTE>

But even this doesn't help if they filled out a zero, and a zero is a valid entry. So, the best way to check if anything at all is entered in the field is to see if it's defined.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


($temp = $field1) =~ s/ //g;
unless(defined($temp)){print "You need to fill in this field}
</pre><HR></BLOCKQUOTE>

The above does not alter the value of $field1 and it allows a value of 0 to be entered.


japhy
Enthusiast

Apr 12, 2000, 8:00 AM


Views: 2074
Re: form data

I suggest you use:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


if ($input =~ /\S/) {
# input has a non-whitespace character in it
}
</pre><HR></BLOCKQUOTE>

Jasmine, just because $temp1 is empty (because it contained all spaces), doesn't make it undef. You'd want to test against the empty string "". But I find the method above to be better and faster.

[This message has been edited by japhy (edited 04-12-2000).]


Jasmine
Administrator

Apr 12, 2000, 2:54 PM


Views: 2074
Re: form data

I stand instructed... thank you Smile