• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

perl+forms...i screwed it up

I screwed up this script somehow...I was hoping someone could help me debug this.  After the form is submitted the first time, I get a blank page.  Nothing shows up on page 2.  If you want to see the script in action, go to www.wwwebsolutions.net/cgi-bin/order.pl
Here's the script:

======================================

#!/usr/bin/perl

use CGI;

$q=new CGI;

## Send the proper MIME header to the browser.
print "Content-type: text/html\n\n";

if ($q->param){
## Read the HTML Form variables into local PERL variables.
## NOTE: the variable names are case sensitive. so fn is NOT the same as FN or Fn or fN.
$page=$q->param('page');
$name=$q->param('name');
$title=$q->param('title');
$company=$q->param('company');
$address=$q->param('address');
$city=$q->param('city');
$state=$q->param('state');
$zip=$q->param('zip');
$phone=$q->param('phone');
$fax=$q->param('fax');
$email=$q->param('email');
$order1=$q->param('order1');
$order2=$q->param('order2');
$order3=$q->param('order3');
$order4=$q->param('order4');
$order5=$q->param('order5');
$order6=$q->param('order6');
$quantity1=$q->param('quantity1');
$quantity2=$q->param('quantity2');
$quantity3=$q->param('quantity3');
$quantity4=$q->param('quantity4');
$quantity5=$q->param('quantity5');
$quantity6=$q->param('quantity6');


## Find out which button the user clicked!!
$action=$q->param('action');

if ($page=~ /^1$/){
#print "<B> Are you sure all the info is correct?</B><P>\n";
$page++;
}elsif ($page=~ /^2$/){
if ($action=~ /^Finish$/){ ## Finish button was clicked
print "OK!! All your info has been accepted!!<P>\n";
## The send out as email part of the code will go here.
# ## Print the users info!!
# print "Name is <B>$name</B><br>\n";
# print "Company is <B>$company</B><br>\n";
exit;
}
}
}else{
$page=1 if (!$page);
}

if ($page=~ /^1$/){ ## Print the First page i.e. HTML form.
print qq{
<html>
<body bgcolor="white">
<form method=post action="$ENV{'SCRIPT_NAME'}">
<table cellpadding=0 cellspacing=0>
<tr valign="top">
<td>
NAME<br>
<input type=text size=40 name=name>
</td>
<td>
TITLE<br>
<input type=text size=30 name=title>
</td>
</tr>
</table>
COMPANY<br>
<input type=text size=70 name=company><br>
ADDRESS<br>
<input type=text size=70 name=address><br>
<table cellspacing=0 cellpadding=0>
<tr valign="top">
<td>
CITY<br>
<input type=text size=30 name=city>
</td>
<td>
STATE<br>
<input type=text size=10 name=state>
</td>
<td>
ZIP<br>
<input type=text size=10 name=zip>
</td>
</tr>
</table>
<table cellspacing=0 cellpadding=0>
<tr valign="top">
<td>
PHONE<br>
<input type=text size=35 name=phone>
</td>
<td>
FAX<br>
<input type=text size=35 name=fax>
</td>
</tr>
</table>

E-MAIL<br>
<input type=text size=70 name=email><br>

<table cellspacing=0 cellpadding=0>
<tr valign="top">
<td>
ORDER #<br>
<input type=text size=10 name=order1 value=$order1><br>
<input type=text size=10 name=order2><br>
<input type=text size=10 name=order3><br>
<input type=text size=10 name=order4><br>
<input type=text size=10 name=order5><br>
<input type=text size=10 name=order6><br>
<input type=hidden name=page>
</td>
<td>
QUANTITY:<br>
<input type=text size=7 name=quantity1><br>
<input type=text size=7 name=quantity2><br>
<input type=text size=7 name=quantity3><br>
<input type=text size=7 name=quantity4><br>
<input type=text size=7 name=quantity5><br>
<input type=text size=7 name=quantity6><br>
</td>
</tr>
</table>

<br>
<input type=submit name=action value="Submit">
</b>
</form>
</body>
</html>
};
}elsif ($page=~ /^2$/){ ## Show the user the info entered & seek confirmation.
print qq{
<body bgcolor="white">
<font size=2 color="red">
<b>Your Name: </b>$name<br>
<b>Your Title: </b>$title<br>
<b>Company: </b>$company<br>
<b>Address:</b>$address<br>
<b>City: </b>$city<br>
<b>State: </b>$state<br>
<b>Zip: </b>$zip<br>
<b>Phone #: </b>$phone<br>
<b>Fax #: </b>$fax<br>
<b>E-Mail Address: </b>$email<br>
<b>Order #1: </b>$order1<br>
<b>Order #2: </b>$order2<br>
<b>Order #3: </b>$order3<br>
<b>Order #4: </b>$order4<br>
<b>Order #5: </b>$order5<br>
<b>Order #6: </b>$order6<br>
<b>Quantity #1: </b>$quantity1<br>
<b>Quantity #2: </b>$quantity2<br>
<b>Quantity #3: </b>$quantity3<br>
<b>Quantity #4: </b>$quantity4<br>
<b>Quantity #5: </b>$quantity5<br>
<b>Quantity #6: </b>$quantity6<br>
 
Is this information correct?<br>
If it is, then click the "Finish" button to e-mail your order.<br>
If it is not correct, click the "Back" button on your browser to change any fields.<br>
<br>
<center>
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'}">
<input type=hidden name=page value=$page>
<input type=submit name=action value="Finish">
</FORM>
</font>
</center>
</body>
};
}

==================================

Thanks
0
GorGor1
Asked:
GorGor1
1 Solution
 
clockwatcherCommented:
Try this:

#!/usr/bin/perl

use CGI;
$q=new CGI;

## Send the proper MIME header to the browser.

print "Content-type: text/html\n\n";

$page = $q->param('page');

if (!$page) {  # No form containing the page variable was submitted
   printHTMLForm();
}
elsif ($page eq "1")   { # Initial form submitted
   printConfirmationPage();
}  
elsif ($page eq "2") { # Confirmation form submitted
   
      print "OK!! All your info has been accepted!!<P>\n";
      ## The send out as email part of the code will go here.
      # ## Print the users info!!
      # print "Name is <B>$name</B><br>\n";
      # print "Company is <B>$company</B><br>\n";
}

# End of main body


sub printHTMLForm {

  print qq{
<html>
<body bgcolor="white">
<form method=post action="$ENV{'SCRIPT_NAME'}">
<table cellpadding=0 cellspacing=0>
<tr valign="top">
<td>
NAME<br>
<input type=text size=40 name=name>
</td>
<td>
TITLE<br>
<input type=text size=30 name=title>
</td>
</tr>
</table>
COMPANY<br>
<input type=text size=70 name=company><br>
ADDRESS<br>
<input type=text size=70 name=address><br>
<table cellspacing=0 cellpadding=0>
<tr valign="top">
<td>
CITY<br>
<input type=text size=30 name=city>
</td>
<td>
STATE<br>
<input type=text size=10 name=state>
</td>
<td>
ZIP<br>
<input type=text size=10 name=zip>
</td>
</tr>
</table>
<table cellspacing=0 cellpadding=0>
<tr valign="top">
<td>
PHONE<br>
<input type=text size=35 name=phone>
</td>
<td>
FAX<br>
<input type=text size=35 name=fax>
</td>
</tr>
</table>

E-MAIL<br>
<input type=text size=70 name=email><br>

<table cellspacing=0 cellpadding=0>
<tr valign="top">
<td>
ORDER #<br>
<input type=text size=10 name=order1><br>
<input type=text size=10 name=order2><br>
<input type=text size=10 name=order3><br>
<input type=text size=10 name=order4><br>
<input type=text size=10 name=order5><br>
<input type=text size=10 name=order6><br>
<input type=hidden name=page value=1>
</td>
<td>
QUANTITY:<br>
<input type=text size=7 name=quantity1><br>
<input type=text size=7 name=quantity2><br>
<input type=text size=7 name=quantity3><br>
<input type=text size=7 name=quantity4><br>
<input type=text size=7 name=quantity5><br>
<input type=text size=7 name=quantity6><br>
</td>
</tr>
</table>

<br>
<input type=submit value="Submit">
</b>
</form>
</body>
</html>
};

}


sub printConfirmationPage {
 $q->import_names;  # import parameters into Q namespace
 print qq{
<body bgcolor="white">
<font size=2 color="red">
<b>Your Name: </b>$Q::name<br>
<b>Your Title: </b>$Q::title<br>
<b>Company: </b>$Q::company<br>
<b>Address:</b>$Q::address<br>
<b>City: </b>$Q::city<br>
<b>State: </b>$Q::state<br>
<b>Zip: </b>$Q::zip<br>
<b>Phone #: </b>$Q::phone<br>
<b>Fax #: </b>$Q::fax<br>
<b>E-Mail Address: </b>$Q::email<br>
<b>Order #1: </b>$Q::order1<br>
<b>Order #2: </b>$Q::order2<br>
<b>Order #3: </b>$Q::order3<br>
<b>Order #4: </b>$Q::order4<br>
<b>Order #5: </b>$Q::order5<br>
<b>Order #6: </b>$Q::order6<br>
<b>Quantity #1: </b>$Q::quantity1<br>
<b>Quantity #2: </b>$Q::quantity2<br>
<b>Quantity #3: </b>$Q::quantity3<br>
<b>Quantity #4: </b>$Q::quantity4<br>
<b>Quantity #5: </b>$Q::quantity5<br>
<b>Quantity #6: </b>$Q::quantity6<br>
 
Is this information correct?<br>
If it is, then click the "Finish" button to e-mail your order.<br>
If it is not correct, click the "Back" button on your browser to change any fields.<br>
<br>
<center>
<FORM METHOD=POST ACTION="$ENV{'SCRIPT_NAME'}">
};

# Restore the form fields (with the exception of page)
# so the next post will carry over their values.

foreach ($q->param) {
  print "<input type=\"hidden\" name=\"$_\" value=\"".$q->param($_)."\">\n" unless ($_ eq "page");
}

print qq{
<input type=hidden name=page value=2>
<input type=submit value="Finish">
</FORM>
</font>
</center>
</body>
};
}
0
 
GorGor1Author Commented:
Thanks, it works great!!  It's much easier to follow too!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now