validation form problems

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

25-Jun-08 20:18
I worked up a validation form patterned after the example on this site. When I run it, I get the following error log entry:

Undefined subroutine &main::display_form called at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 18.


The first 30 or so lines are:

#!/usr/bin/perl

use CGI;

# Create the CGI object
$query = new CGI;

# Output the HTTP header
print $query->header ( );
#10...
# Process form if submitted; otherwise display it
if ( $query->param("submit") )
{
process_form ( );
}
else
{
display_form ( );
}
#20...
sub process_form
{
if ( validate_form ( ) )
{
print <<END_HTML;
<html><head><title>Welcome to McHenry"s Soberfest Registration Confirmation Page</title></head>
<body>
<p class="next">Thanks for filling in our form!<br>
You will need to return to the form and fill it out for each registrant that you have paid for.<br>
#30...
This is so that we can match the PayPal receipt to your registration.<br>To Complete Registering Multiple Guests, <a

href="../register/register.php">Click Here</a>.<br><br>
Your Registration will be processed immediately.<br> Your Conference Packet will be available, as always, at the

Registration Table at the Conference.<br><br>
See you there!</p>
</body></html>
END_HTML
}
}

I get a blank page with the file name in the title.

I am a bit confused...can you help?

Doug
26-Jun-08 02:25
Hi Doug,

Please post the entire script so that we can see where the problem lies.

Cheers
Matt

--
Matt Doyle
ELATED - Helping people make websites since 1997!
http://www.elated.com/
26-Jun-08 04:26
here it is:

#!/usr/bin/perl -w

use CGI;

# Create the CGI object
$query = new CGI;

# Output the HTTP header
print $query->header ( );
#10...
# Process form if submitted; otherwise display it

if ( $query->param("submit") )
{
process_form ( );
}
else
{
display_form ( );
}
#20...
sub process_form
{
if ( validate_form ( ) )
{
print <<END_HTML;
<html><head><title>Welcome to McHenry"s Soberfest Registration Confirmation Page</title></head>
<body>
<p class="next">Thanks for filling in our form!<br>
You will need to return to the form and fill it out for each registrant that you have paid for.<br>
#30...
This is so that we can match the PayPal receipt to your registration.<br>To Complete Registering Multiple Guests, <a

href="../register/register.php">Click Here</a>.<br><br>
Your Registration will be processed immediately.<br> Your Conference Packet will be available, as always, at the

Registration Table at the Conference.<br><br>
See you there!</p>
</body></html>
END_HTML
}
}
#40...
sub validate_form
{
# Capture the form results
$email = $query->param("email");
$firstname = $query->param("first_name");
$lastname = $query->param("last_name");
$address = $query->param("address");
$city = $query->param("city");
$state = $query->param("state");
#50...
$zip = $query->param("zip");
$phone = $query->param("phone");
$specneeds = $query->param("specneeds");
$AA = $query->param("AA");
$AAunder = $query->param("AAunder");
$Alanon = $query->param("Alanon");
$ATeen = $query->param("AlTeen");
$Under8=$query->param("Under8");
$Payor=$query->param("Payor");
# Filter the form results
#60...
$email = filter_header_field ( $email);
$firstname = filter_field ( $first_name );
$lastname = filter_field ($last_name );
$address = filter_field ($address);
$city = filter_field ($city);
$state = filter_field ($state);
$zip = filter_field ($zip);
$phone = filter_field ($phone);
$specneeds = filter_field ($specneeds);
$AA = filter_field ($AA);
#70...
$AAunder = filter_field ($AAunder);
$Alanon = filter_field ($Alanon);
$ATeen = filter_field($ATeen);
$Under8 = filter_field($Under8);
$Payor = filter_field($Payor);

$error_message = "";
$error_message .= "Please enter your email adress<br>" if ( !$email );
$error_message .= "Please enter your first name<br>" if ( !$firstname);
#80...
$error_message .= "Please enter your last name<br>" if ( !$lastname );
$error_message.="Please enter your address<br>" if (!$address);
$error_message.="Please enter your city<br>" if (!$city);
$error_message.="Please enter your state<br>" if(!$state);
$error_message.="Please enter your zip code<br>"if (!$zip);
$error_message.="Please enter your phone number<br>" if (!$phone);
$error_message.="Please enter any Special Needs. If none, enter 'none'<br>" if (!$specneeds);
$error_message.="Please specify payor<br>" if (!$payor);

if ( $error_message )
#90...
{
# Errors with the form - redisplay it and return failure
display_form ( $error_message, $email, $firstname, $lastname, $address, $city, $state, $zip, $phone, $payor);
return 0;
}
else
{
# Form OK - return success
return 1;
}
}
#100..


sub display_form
{
$error_message = shift;
$email = shift;
$email = shift;
$firstname = shift;
$lastname =shift;
$address = shift;
#110..
$city = shift;
$state = shift;
$phone = shift;
$specneeds = shift;
$payor = shift;
}
# Display the form

print <<END_HTML;
<html>
<head>
<title>Welcome to McHenry's Soberfest Online Registration Page</title>
<!---- Edit This Line Only ------>
<!...120...>
<!---- Site Content Shell, do not edit below this line ------>
<link href="../includes/basics.css" rel="stylesheet" type="text/css" media="all" />
</head>

<?php include('../includes/header.php'); ?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<!-- In this main body table there are 3 columns --->
<tr>
<td width="150" valign="top">
<!...130...>
<?php include('../includes/menu.php'); ?>
<!-- end menu cell -->
</td>
<td width="15"><!--spacer --></td>
<!---- Do Not Edit Above this Line ------>
<td valign="top"><!--- begin insert of content here --->

<p class="next">Welcome to the McHenry's Soberfest Online Registration form.<br>
Your transaction with PayPal has been completed sucsessfully! You should be receiving e-mail confirmation from PayPal

shortly.<br>
<!...140...>
You are only a few minutes away from being registered for the Conference.<br><br>
This form will be used by the Registration sub-committee to assign seating at the Banquet, assess and meet all Special

Needs of our guests and update the Registration database for next year's Conference.<br><br>Please fill in all of the

following fields.<br><br>

</p>
<!--- begin registration form --->
<form action="Validation_Form.cgi" method="post" enctype="text/plain">
Email Address:<br>
<input type="text" name="email"> <br>
<!...150...>
First name: <br>
<input type="text" name="firstname"> <br>
Last name:<br>
<input type="text" name="lastname"><br>
Address: <br>
<input type="text" name="address"><br><br>
City:
<input type="text" name="city">
State:
<input type="text" name="state" size="2">
<!...160...>
Zip Code:
<input type="text" name="zip" size="5"><br><br>
Phone: <input type="text" name="phone">
Special Needs: <input type="text" name="specneeds"><br><br>
<input type="radio" name="type" value="AA"> AA
<br>
<input type="radio" name="type" value="AAunder"> AA (under 18 years of age)
<br>
<input type="radio" name="type" value="Alanon"> AL-ANON
<br>
<!...170...>
<input type="radio" name="type" value="ATeen"> ALATEEN
<br>
<input type="radio" name="type" value="Under8">Child under 8 years of age
<br><br>
Please select the number of registrations you paid for via PayPal before accessing this registration form.<br>
<select name="RegCount">
<option value="1">1 Registration</option>
<option value="2">2 Registrations</option>
<option value="3">3 Registrations</option>
<option value="4">4 Registrations</option>
<!...180...>
<option value="5">5 Registrations</option>
<option value="6">6 Registrations</option>
<option value="7">7 Registrations</option>
<option value="8">8 Registrations</option>
<option value="9">9 Registrations</option>
<option value="10">10 Registrations</option>
</select>
<br><br>
Last Name of Payor (if different than yours)<br>
<!...190...>
<input type="text" name="payor"<br><br>
<p class="next">
Please remember, Persons under the age of 18 MUST be accompanied throughout the conference
by a parent or legal guardian.<br> Alateens must be 8 years old to register and attend meetings.</p>
<br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>

</td>
<!...200...>
</tr>
</table>
<?php include('../includes/footer.php'); ?>
</html>
END_HTML
}
# Functions for filtering user input

sub filter_field
{
my $field = shift;
#210..
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
return $field;
}

sub filter_header_field
#220..
{
$field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
$field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}
}
26-Jun-08 09:24
There are 2 problems that I can see:

1. You have an extra curly bracket at line 125:

-----
$payor = shift;
}
# Display the form
-----

Should be:

-----
$payor = shift;

# Display the form
-----

2. You have an extra curly bracket at line 258:

-----
return $field;
}
}
-----

Should be:

-----
return $field;
}
-----

Matt


--
Matt Doyle
ELATED - Helping people make websites since 1997!
http://www.elated.com/
26-Jun-08 19:33
Matt,

I tried deleting the right curly, and got error that it was missing...

I enabled warnings and strict checking.

Here is current script:

#!/usr/bin/perl -w

use CGI;

use strict;

# Create the CGI object
my $query = new CGI;

# Output the HTTP header
print $query->header ( );

#10...
# Process form if submitted; otherwise display it

if ( $query->param("submit") )
{
process_form ( );
}
else
{
display_form ( );
}
#20...
sub process_form
{
if ( validate_form ( ) )
{
print <<END_HTML;
<html><head><title>Welcome to McHenry"s Soberfest Registration Confirmation Page</title></head>
<body>
<p class="next">Thanks for filling in our form!<br>
You will need to return to the form and fill it out for each registrant that you have paid for.<br>
#30...
This is so that we can match the PayPal receipt to your registration.<br>To Complete Registering Multiple Guests, <a

href="../register/register.php">Click Here</a>.<br><br>
Your Registration will be processed immediately.<br> Your Conference Packet will be available, as always, at the

Registration Table at the Conference.<br><br>
See you there!</p>
</body></html>
END_HTML
}
}
#40...
sub validate_form

# Capture the form results
{
my $email = $query->param("email");
my $firstname = $query->param("first_name");
my $lastname = $query->param("last_name");
my $address = $query->param("address");
my $city = $query->param("city");
my $state = $query->param("state");
#50...
my $zip = $query->param("zip");
my $phone = $query->param("phone");
my $specneeds = $query->param("specneeds");
my $AA = $query->param("AA");
my $AAunder = $query->param("AAunder");
my $Alanon = $query->param("Alanon");
my $ATeen = $query->param("AlTeen");
my $Under8=$query->param("Under8");
my $Payor=$query->param("Payor");
# Filter the form results
#60...
my $email = filter_header_field ( $email);
my $firstname = filter_field ( $first_name );
my $lastname = filter_field ($last_name );
my $address = filter_field ($address);
my $city = filter_field ($city);
my $state = filter_field ($state);
my $zip = filter_field ($zip);
my $phone = filter_field ($phone);
my $specneeds = filter_field ($specneeds);
my $AA = filter_field ($AA);
#70...
my $AAunder = filter_field ($AAunder);
my $Alanon = filter_field ($Alanon);
my $ATeen = filter_field($ATeen);
my $Under8 = filter_field($Under8);
my $Payor = filter_field($Payor);

my $error_message = "";

$error_message .= "Please enter your email adress<br>" if ( !$email );
$error_message .= "Please enter your first name<br>" if ( !$first_name);
#80...
$error_message .= "Please enter your last name<br>" if ( !$last_name );
$error_message.="Please enter your address<br>" if (!$address);
$error_message.="Please enter your city<br>" if (!$city);
$error_message.="Please enter your state<br>" if(!$state);
$error_message.="Please enter your zip code<br>"if (!$zip);
$error_message.="Please enter your phone number<br>" if (!$phone);
$error_message.="Please enter any Special Needs. If none, enter 'none'<br>" if (!$specneeds);
$error_message.="Please specify payor<br>" if (!$payor);

if ( $error_message )
#90...
{
# Errors with the form - redisplay it and return failure
display_form ( $error_message, $email, $firstname, $lastname, $address, $city, $state, $zip, $phone, $payor);
return 0;
}
else
{
# Form OK - return success
return 1;
}
}
#100..


sub display_form
{
my $error_message = shift;
my $email = shift;
my $firstname = shift;
my $lastname =shift;
my $address = shift;
#110..
my $city = shift;
my $state = shift;
my $phone = shift;
my $specneeds = shift;
my $payor = shift;

# Display the form

print <<END_HTML;
<html>
<head>
<title>Welcome to McHenry's Soberfest Online Registration Page</title>
<!---- Edit This Line Only ------>
<!...120...>
<!---- Site Content Shell, do not edit below this line ------>
<link href="../includes/basics.css" rel="stylesheet" type="text/css" media="all" />
</head>

<?php include('../includes/header.php'); ?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<!-- In this main body table there are 3 columns --->
<tr>
<td width="150" valign="top">
<!...130...>
<?php include('../includes/menu.php'); ?>
<!-- end menu cell -->
</td>
<td width="15"><!--spacer --></td>
<!---- Do Not Edit Above this Line ------>
<td valign="top"><!--- begin insert of content here --->

<p class="next">Welcome to the McHenry's Soberfest Online Registration form.<br>
Your transaction with PayPal has been completed sucsessfully! You should be receiving e-mail confirmation from PayPal

shortly.<br>
<!...140...>
You are only a few minutes away from being registered for the Conference.<br><br>
This form will be used by the Registration sub-committee to assign seating at the Banquet, assess and meet all Special

Needs of our guests and update the Registration database for next year's Conference.<br><br>Please fill in all of the

following fields.<br><br>

</p>
<p>$error_message</p>

<!--- begin registration form --->
<form action="Validation_Form.cgi" method="post" enctype="text/plain">
Email Address:<br>
<input type="text" name="email"> <br>
<!...150...>
First name: <br>
<input type="text" name="firstname"> <br>
Last name:<br>
<input type="text" name="lastname"><br>
Address: <br>
<input type="text" name="address"><br><br>
City:
<input type="text" name="city">
State:
<input type="text" name="state" size="2">
<!...160...>
Zip Code:
<input type="text" name="zip" size="5"><br><br>
Phone: <input type="text" name="phone">
Special Needs: <input type="text" name="specneeds"><br><br>
<input type="radio" name="type" value="AA"> AA
<br>
<input type="radio" name="type" value="AAunder"> AA (under 18 years of age)
<br>
<input type="radio" name="type" value="Alanon"> AL-ANON
<br>
<!...170...>
<input type="radio" name="type" value="ATeen"> ALATEEN
<br>
<input type="radio" name="type" value="Under8">Child under 8 years of age
<br><br>
Please select the number of registrations you paid for via PayPal before accessing this registration form.<br>
<select name="RegCount">
<option value="1">1 Registration</option>
<option value="2">2 Registrations</option>
<option value="3">3 Registrations</option>
<option value="4">4 Registrations</option>
<!...180...>
<option value="5">5 Registrations</option>
<option value="6">6 Registrations</option>
<option value="7">7 Registrations</option>
<option value="8">8 Registrations</option>
<option value="9">9 Registrations</option>
<option value="10">10 Registrations</option>
</select>
<br><br>
Last Name of Payor (if different than yours)<br>
<!...190...>
<input type="text" name="payor"<br><br>
<p class="next">
Please remember, Persons under the age of 18 MUST be accompanied throughout the conference
by a parent or legal guardian.<br> Alateens must be 8 years old to register and attend meetings.</p>
<br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>

</td>
<!...200...>
</tr>
</table>
<?php include('../includes/footer.php'); ?>
</html>
END_HTML
}
# Functions for filtering user input

sub filter_field
{
my $field = shift;
#210..
my $field =~ s/From://gi;
my $field =~ s/To://gi;
my $field =~ s/BCC://gi;
my $field =~ s/CC://gi;
my $field =~ s/Subject://gi;
my $field =~ s/Content-Type://gi;
return $field;
}

sub filter_header_field
#220..
{
my $field = shift;
my $field =~ s/From://gi;
my $field =~ s/To://gi;
my $field =~ s/BCC://gi;
my $field =~ s/CC://gi;
my $field =~ s/Subject://gi;
my $field =~ s/Content-Type://gi;
my $field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}
}


Here is current error log:

Global symbol "$error_message" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$error_message" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$email" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$firstname" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$lastname" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$address" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$city" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$state" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$zip" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$phone" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$payor" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$error_message" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$email" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$firstname" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$lastname" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$address" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$city" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$state" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$phone" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$specneeds" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$payor" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Global symbol "$error_message" requires explicit package name at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 29.
Missing right curly or square bracket at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 254, at end of line
/home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi has too many errors.
[Thu Jun 26 11:24:22 2008] [error] [client 64.12.117.199] Premature end of script headers: /var/chroot/home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi


I know that this is a long post, but I am really having fun with this script, and I need some direction.

Thanx for helping,

Doug
26-Jun-08 22:26
You only deleted the curly bracket at line 125. You still have the one at 258.

--
Matt Doyle
ELATED - Helping people make websites since 1997!
http://www.elated.com/
02-Jul-08 05:51
Sorry for the delay in replying...vacation (holiday).

This will demonstrate how much of a newbie I am. When I run my repaired script, using the use diagnostics, error log says:

Use of uninitialized value in concatenation (.) or string at
/home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 133 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.


Here's my questions:

1) How does one count lines? Are they counted relative to Perl script only, or are they, in fact, each individual line of printed material (including space "lines" between script)?

2) Given the script as it appears above in this thread (minus the curlys you pointed out before) what is it that Perl is saying is undefined, and how do I correct this error.

When run, I get the form, but it neither validates nor produces an email/Thankyou page.

I really appreciate the help which you've given me.

Doug

03-Jul-08 01:04
1) Use a text editor that shows you which line you're on! Then you can find out exactly what line 133 is.

2) Possibly one of your form parameters is not being passed into your script (missing/misspelled form field name in the HTML?), which results in an undefined value passed to the output. Make sure all your form fields are being passed correctly to the script. You can also use eg:

my $email = $query->param("email") || "";

to make sure that the variable is always initialized (even if it's initialized to "").

Also you have some inconsistencies in your variable names eg:

$firstname = $query->param("first_name");

Best to use the same variable name as the form parameter name! It's possible that you've misspelled a variable somewhere in your script, and that's causing the problem.

BTW you can't use PHP includes in a Perl script:

<?php include('../includes/header.php'); ?>

Matt

--
Matt Doyle
ELATED - Helping people make websites since 1997!
http://www.elated.com/
07-Jul-08 04:12
OK,

I acquired a text editor which allows me to number the lines (I know, I should have been using it all along...:-( ) More on that...

I have reviewed my script, and removed all php includes (as you noted they didn't work anyway).

I am getting the following error:

"Use of unitialized value in substitution (s///)at..."which refers me to the lines that the form filters are located on.

# Functions for filtering user input

sub filter_field
{
my $field = shift;
my $field =~ s/From://gi;
my $field =~ s/To://gi;
my $field =~ s/BCC://gi;
my $field =~ s/CC://gi;
my $field =~ s/Subject://gi;
my $field =~ s/Content-Type://gi;
return $field;
}

sub filter_header_field
#220..
{
my $field = shift;
my $field =~ s/From://gi;
my $field =~ s/To://gi;
my $field =~ s/BCC://gi;
my $field =~ s/CC://gi;
my $field =~ s/Subject://gi;
my $field =~ s/Content-Type://gi;
my $field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}

What would fix this besides using the "my" declaration?

There is another error message, but I was thinking it would be best to solve these problems on at a time.

Thanks for all the help so far; its been a real learning experience for me to be sure!

Doug
07-Jul-08 05:36
This means that you're passing uninitialized values (presumably from your form fields) to these functions. As I said, this will happen if you have misspelled/mistyped your form field names or variable names at any point.

Glancing through your form I can see the following problems:

- 'first_name'/'last_name' are sometimes spelled 'firstname'/'lastname'

- 'payor' is sometimes spelled 'Payor' (Perl is case-sensitive; these are 2 different variables as far as Perl is concerned)

- You've missed out 'name="submit"' from your "Send" button:

<input type="submit" value="Send">

should be:

<input type="submit" name="submit" value="Send">

- You've used an encoding type of "text/plain" for your form, which will break the form sending entirely. Remove this attribute.

- You'll also want to include $error_message when outputting your form, otherwise visitors won't be able to see which fields they've filled in incorrectly.

- Also, don't put 'my' in front of every instance of '$field' like you've done in those functions. 'my' should only be before the first instance of the variable name.

Matt

[Edited by matt on 07-Jul-08 05:39]

--
Matt Doyle
ELATED - Helping people make websites since 1997!
http://www.elated.com/
12-Jul-08 01:23
Matt,

I have made the changes you sugested. I aplolgise ahead of time because this is going to be another long post.

Entire code looks like this:

#!/usr/bin/perl

use CGI;

use diagnostics;

# Create the CGI object
my $query = new CGI;



# Output the HTTP header
print $query->header ( );


sub process_form
{
if ( validate_form ( ) )
{
print<<END_HTML;
<html><head><title>Welcome to McHenry"s Soberfest Registration Confirmation Page</title></head>
<body>
<p class="next">Thanks for filling in our form!<br>
You will need to return to the form and fill it out for each registrant that you have paid for.<br>
This is so that we can match the PayPal receipt to your registration.<br>To Complete Registering Multiple Guests, <a href="../register/register.php">Click Here</a>.<br><br>
Your Registration will be processed immediately.<br> Your Conference Packet will be available, as always, at the Registration Table at the Conference.<br><br>
See you there!</p>
</body></html>
END_HTML
}
}


# Display the form

display_form( );

print<<END_HTML;
<html>

<title>Welcome to McHenry's Soberfest Online Registration Page</title>

<!---- Do Not Edit Above this Line ------>
<td valign="top"><!--- begin insert of content here --->

<p class="next">Welcome to the McHenry's Soberfest Online Registration form.<br>
Your transaction with PayPal has been completed sucsessfully! You should be receiving e-mail confirmation from PayPal shortly.<br>
You are only a few minutes away from being registered for the Conference.<br><br>
This form will be used by the Registration sub-committee to assign seating at the Banquet, assess and meet all Special Needs of our guests and update the Registration database for next year's Conference.<br><br>Please fill in all of the following fields.<br><br></p>

<p> $error_message </p>

<!--- begin registration form --->
<form action="Validation_Form.cgi" method="post">
Email Address:<br>
<input type="text" name="email" value=$email> <br>
First name: <br>
<input type="text" name="firstname" value=$firstname> <br>
Last name:<br>
<input type="text" name="lastname" value=$lastname><br>
Address: <br>
<input type="text" name="address" value=$address><br><br>
City:
<input type="text" name="city" value=$city>
State:
<input type="text" name="state" size="2" value=$state>
Zip Code:
<input type="text" name="zip" size="5" value=$zip><br><br>
Phone: <input type="text" name="phone" value=$phone>
Special Needs: <input type="text" name="specneeds" value=$specneeds><br><br>
<input type="radio" name="type" value="AA"> AA
<br>
<input type="radio" name="type" value="$AAunder"> AA (under 18 years of age)
<br>
<input type="radio" name="type" value="$Alanon"> AL-ANON
<br>
<input type="radio" name="type" value="$ATeen"> ALATEEN
<br>
<input type="radio" name="type" value="$Under8">Child under 8 years of age
<br><br>
Please select the number of registrations you paid for via PayPal before accessing this registration form.<br>
<select name="RegCount">
<option value="1">1 Registration</option>
<option value="2">2 Registrations</option>
<option value="3">3 Registrations</option>
<option value="4">4 Registrations</option>
<!...180...>
<option value="5">5 Registrations</option>
<option value="6">6 Registrations</option>
<option value="7">7 Registrations</option>
<option value="8">8 Registrations</option>
<option value="9">9 Registrations</option>
<option value="10">10 Registrations</option>
</select>
<br><br>
Last Name of Payor (if different than yours)<br>
<input type="text" name="payor" value=$payor> <br><br>
<p class="next">
Please remember, Persons under the age of 18 MUST be accompanied throughout the conference
by a parent or legal guardian.<br> Alateens must be 8 years old to register and attend meetings.</p>
<br>
<input type="submit" name="submit" value="Send">
<input type="reset" name="reset" value="Reset">
</form>
</html>
END_HTML
# Process form if submitted; otherwise display it

if ( $query->param("Send") )
{
process_form ( );
}
else
{
display_form ( );
}
sub display_form

{
$error_message = shift;
$email = shift;
$firstname = shift;
$lastname =shift;
$address = shift;
$city = shift;
$state = shift;
$phone = shift;
$specneeds = shift;
$payor = shift;
}

sub validate_form
{
# Capture the form results

$email = $query->param("email");
$firstname = $query->param("firstname");
$lastname = $query->param("lastname");
$address = $query->param("address");
$city = $query->param("city");
$state = $query->param("state");
$zip = $query->param("zip");
$phone = $query->param("phone");
$specneeds = $query->param("specneeds");
$AA = $query->param("AA");
$AAunder = $query->param("AAunder");
$Alanon = $query->param("Alanon");
$ATeen = $query->param("ATeen");
$Under8=$query->param("Under8");
$payor=$query->param("payor");

}
{
if ( $error_message )
# Errors with the form - redisplay it and return failure
{
display_form ($error_message, $email, $firstname, $lastname, $address,
$city, $state, $zip, $phone, $payor);
return (0);
}
else
# Form OK - return success
{
return (1);
}
}

my $error_message = "";

$error_message.="Please enter your email adress<br>" if (!$email);
$error_message.="Please enter your first name<br>" if (!$firstname);
$error_message.="Please enter your last name<br>" if (!$lastname );
$error_message.="Please enter your address<br>" if (!$address);
$error_message.="Please enter your city<br>" if (!$city);
$error_message.="Please enter your state<br>" if(!$state);
$error_message.="Please enter your zip code<br>"if (!$zip);
$error_message.="Please enter your phone number<br>" if (!$phone);
$error_message.="Please enter any Special Needs. If none, enter 'none'<br>" if (!$specneeds);
$error_message.="Please specify payor<br>" if (!$payor);



#Mail The Results
{
open ( MAIL,"| /usr/lib/sendmail -t" );
print MAIL "From: $email\n";
print MAIL "To: Cotechnical\@soberfest.org\n";
print MAIL "CC: Dougger57\@aol.com\n";
print MAIL "Subject: Form Submission\n\n";
print MAIL "$email\n";
print MAIL "$firstname\n";
print MAIL "$lastname\n";
print MAIL "$address\n";
print MAIL "$city\n";
print MAIL "$state\n";
print MAIL "$zip\n";
print MAIL "$phone\n";
print MAIL "$specneeds\n";
print MAIL "$AA\n";
print MAIL "$AAunder\n";
print MAIL "$Alanon\n";
print MAIL "$ATeen\n";
print MAIL "$Under8\n";
print MAIL "$payor\n";
print MAIL "\n.\n";
close ( MAIL );
}

#Filter the form results
{
$email = filter_header_field ($email);
$firstname = filter_field ($firstname);
$lastname = filter_field ($lastname );
$address = filter_field ($address);
$city = filter_field ($city);
$state = filter_field ($state);
$zip = filter_field ($zip);
$phone = filter_field ($phone);
$specneeds = filter_field ($specneeds);
$AA = filter_field ($AA);
$AAunder = filter_field ($AAunder);
$Alanon = filter_field ($Alanon);
$ATeen = filter_field($ATeen);
$Under8 = filter_field($Under8);
$payor = filter_field($payor);
}
# Functions for filtering user input

sub filter_field
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
return $field;
}

sub filter_header_field
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
$field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}

Error log looks like this:

Use of uninitialized value in concatenation (.) or string at
/home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 38 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.

To help you figure out what was undefined, perl tells you what operation
you used the undefined value in. Note, however, that perl optimizes your
program and the operation displayed in the warning may not necessarily
appear literally in your program. For example, "that $foo" is
usually optimized into "that " . $foo, and the warning will refer to
the concatenation (.) operator, even though there is no . in your
program.

Can't return outside a subroutine at
/home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 164 (#2)
(F) The return statement was executed in mainline code, that is, where
there was no subroutine call to return out of. See perlsub.

Uncaught exception from user code:
Can't return outside a subroutine at /home/content/s/f/t/sftechnical/html/register/Validation_Form.cgi line 164.


The form is displayed, but won't validate nor mail.

Once again, thank you in advance for your help!

Doug
12-Jul-08 10:18
Dear oh dear, this code's getting buggier and buggier!

The "Can't return outside a subroutine" error is fairly self-explanatory. Somehow, half your code is no longer in subroutines. For example:

sub validate_form
{
# Capture the form results

$email = $query->param("email");
$firstname = $query->param("firstname");
$lastname = $query->param("lastname");
$address = $query->param("address");
$city = $query->param("city");
$state = $query->param("state");
$zip = $query->param("zip");
$phone = $query->param("phone");
$specneeds = $query->param("specneeds");
$AA = $query->param("AA");
$AAunder = $query->param("AAunder");
$Alanon = $query->param("Alanon");
$ATeen = $query->param("ATeen");
$Under8=$query->param("Under8");
$payor=$query->param("payor");

}
{
if ( $error_message )
# Errors with the form - redisplay it and return failure
{
display_form ($error_message, $email, $firstname, $lastname, $address,
$city, $state, $zip, $phone, $payor);
return (0);
}
else
# Form OK - return success
{
return (1);
}
}


You've closed the sub here:

$payor=$query->param("payor");

}

... and the rest of your code is outside the sub! And you can't use 'return (1)' outside of a sub.

(The curly braces ( { } ) define where the subroutines, if/else blocks, etc begin and end.)

Also you really want the 'Mail The Results' and 'Filter the form results' code to be inside the process_form() sub, not validate_form().

In addition, the calls to filter_header_field() and filter_field() should be *before* you call sendmail, not after. The point of the filtering is to remove any spammy headers before the email is passed to sendmail.

Hope that helps!
Matt



--
Matt Doyle
ELATED - Helping people make websites since 1997!
http://www.elated.com/

 
New posts
Old posts

Follow Elated