Solved

perl+forms...i screwed it up

Posted on 2000-05-17
2
172 Views
Last Modified: 2010-03-05
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
Comment
Question by:GorGor1
2 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 20 total points
ID: 2819550
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
 
LVL 1

Author Comment

by:GorGor1
ID: 2819597
Thanks, it works great!!  It's much easier to follow too!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now