Hello everyone! I am dabbling in processing forms using Perl and having only just begun, I am already having problems. Go figure. :-)
Top begin with, here it the form's html, its nothing at all complicated:
-
<div id="formcontent">
-
<h3>The New Information Gathering Form</h3>
-
<form action="./cgi-bin/process_form.cgi" method="post">
-
<fieldset>
-
<legend><strong>Personal Information</strong></legend>
-
<label for="firstname">First Name:</label>
-
<input type="text" id="firstname" maxlength="25"/><br />
-
<label for="lastname">Last Name:</label>
-
<input type="text" id="lastname" maxlength="30"/><br />
-
<label>Date Of Birth:</label>
-
<label for="dobmonth" class="date">Month</label>
-
<input type="text" maxlength="2" id="dobmonth" size="2" />
-
<label for="dobday" class="date">Day</label>
-
<input type="text" maxlength="2" id="dobday" size="2" />
-
<label for="dobyear" class="date">Year</label>
-
<input type="text" maxlength="4" id="dobyear" size="4" /><br/>
-
<label>Gender:</label>
-
<input type="radio" name="gender" value="Male" /> <label for="gender" class="sex">Male</label>
-
<input type="radio" name="gender" value="Female" /> <label for="gender" class="sex">Female</label><br />
-
-
</fieldset>
-
<br />
-
<fieldset>
-
<legend><strong>Contact Information</strong></legend>
-
<label for="address1">Address1:</label>
-
<input type="text" id="address1" /><br />
-
<label for="address1">Address2:</label>
-
<input type="text" id="address2" /><br />
-
<label for="city">City:</label>
-
<input type="text" id="city" /><br />
-
<label for="state">State:</label>
-
<input type="text" id="state" /><br />
-
<label for="zipcode">Zip Code:</label>
-
<input type="text" id="zipcode" /><br />
-
<label for="phone">Phone #:</label>
-
<input type="text" id="phone" alt="In the format XXX-XXX-XXXX" /><label class="format">(XXX-XXX-XXXX)</label><br />
-
</fieldset>
-
<br />
-
<fieldset>
-
<legend><strong>Form Control</strong></legend>
-
<input type="submit" value="Submit" class="submit" />
-
<input type="reset" value="Reset Form" />
-
</fieldset>
-
</form>
-
</div>
-
Please know that with the css I have, it will look a lot prettier. If you want to see the form in all its glory, please see
this link
If you put in information and hit submit, you will see that it errors. No, there isn't a 500 page as of yet, but that's not the issue. If I execute the script by hand, I get the following error:
[code]
[Mon Aug 18 10:41:57 2008] process_form.cgi: Use of uninitialized value in read at ./process_form.cgi line 22.
[code]
The following is the script that I have put together to process the above form after submission.
-
#!/usr/local/bin/perl
-
-
# The following line needed as the host puts a perl
-
# directory in your site home directory that contains
-
# ALL the Perl modules that are installed on the site.
-
# Its basically everything.
-
use lib '/home/jkwebdev/perl';
-
-
##### use statements #####
-
use strict;
-
use warnings;
-
use CGI::Carp qw(fatalsToBrowser);
-
-
##### Variable Declarations #####
-
my @pairs;
-
my $pair;
-
my $value;
-
my $name;
-
my %form;
-
my $buffer;
-
-
#####
-
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
-
-
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
-
-
@pairs = split(/&/, $buffer);
-
-
foreach $pair (@pairs) {
-
($name, $value) = split(/=/, $pair);
-
$value =~ tr/+/ /;
-
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
-
$form{$name} = $value;
-
}
-
-
}
-
-
for my $key ( keys %form ) {
-
my $value = $form{$key};
-
print "$key => $value\n";
-
}
-
All I want to do at first is print out all of the values so I can get a visual on it and that isn't even working.
Any help will be greatly appreciated!
Best regards,
Jeff