Solved

perl+forms...i screwed it up

Posted on 2000-05-17
2
173 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

914 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

12 Experts available now in Live!

Get 1:1 Help Now