CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Question on cgi-pm

 



Dreamer
Deleted

Feb 11, 2000, 8:43 PM

Post #1 of 3 (774 views)
Question on cgi-pm Can't Post

I have written a program using cgi.pm using my old cgi program as a basis. There are a few questions I have.

#1 ... I have choices (radio buttons, but only radio_group would work) to pick from on my pages, and it is automatically selecting the bottom choice. I would like it to select the top choice automatically and can't figure out how.

#2 ... From these choices are price associations, which when the pages are finally submitted will give the total price.

#3 ... I want it to sent me an email on the final submit. Only problem now it it sends me an email when every page is pulled (there are about 11 pages generated from my program)
!

Any help with this would be appreciated.
TIA,
Dreamer


Cure
User

Feb 12, 2000, 12:45 PM

Post #2 of 3 (774 views)
Re: Question on cgi-pm [In reply to] Can't Post

Hi Dreamer

Can you post your code that your having problems with so I can check it out..
Thxs:

Cure


Dreamer
Deleted

Feb 12, 2000, 2:22 PM

Post #3 of 3 (774 views)
Re: Question on cgi-pm [In reply to] Can't Post

Ok Cure ... thanks.
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

# script: test.cgi
use CGI qw/:standard :html3/;
$foo = new CGI;
$recipient1 = 'trinity@trinitypages.com';
$mailprog = '/usr/bin/sendmail';
$timezone = 'Pacific Time';

# this defines the contents of the fill out forms
# on each page.
@PAGES = ('Personal','Size','Addons','Graphics','Domain','Host','HostPlus','NoHost','NoHostPlus','Promotion','PPlus','Confirmation');

# accumulate the field names into %ALL_FIELDS;
foreach (values %FIELDS) {
grep($ALL_FIELDS{$_}++,@$_);
}

# figure out what page we're on and where we're heading.
$current_page = calculate_page(param('page'),param('go'));
$page_name = $PAGES[$current_page];

print_header();
print_personal($current_page) if $page_name eq 'Personal';
print_size($current_page) if $page_name eq 'Size';
print_addons($current_page) if $page_name eq 'Addons';
print_graphics($current_page) if $page_name eq 'Graphics';
print_domain($current_page) if $page_name eq 'Domain';
print_host($current_page) if $page_name eq 'Host';
print_hostplus($current_page) if $page_name eq 'HostPlus';
print_nohost($current_page) if $page_name eq 'NoHost';
print_nohostplus($current_page) if $page_name eq 'NoHostPlus';
print_promotion($current_page) if $page_name eq 'Promotion';
print_pplus($current_page) if $page_name eq 'PPlus';
print_confirmation($current_page) if $page_name eq 'Confirmation';
print_footer();
&price;
&send_mail;
print end_html;

# CALCULATE THE CURRENT PAGE
sub calculate_page {
my ($prev,$dir) = @_;
return 0 if $prev eq ''; # start with first page
return $prev + 1 if $dir eq 'Submit';
return $prev + 1 if $dir eq 'On To Next Page';
}

# CALCULATE THE PRICE
sub price {
if ($FORM{'size'} eq "large") { $Sprice=700; }
elsif ($FORM{'size'} eq "medium") { $Sprice=300; }
elsif ($FORM{'size'} eq "small") { $Sprice=125; }
else { $Sprice=0; }

if ($FORM{'type'} eq "frames") { $Dprice=25; }
elsif ($FORM{'type'} eq "java") { $Dprice=75; }
elsif ($FORM{'type'} eq "flash") { $Dprice=125; }
else { $Dprice=0; }

if ($FORM{'graph'} eq "small") { $Cprice=90; }
elsif ($FORM{'graph'} eq "large") { $Cprice=180; }
elsif ($FORM{'graph'} eq "both") { $Cprice=270; }
else { $Cprice=0; }

if ($FORM{'promo'} eq "yes") { $Pprice=75; }
else { $Pprice=0; }

if ($FORM{'pplus'} eq "1") { $Aprice=75; }
elsif ($FORM{'pplus'} eq "3") { $Aprice=450; }
elsif ($FORM{'pplus'} eq "6") { $Aprice=975; }
elsif ($FORM{'pplus'} eq "year") { $Aprice=2025; }
else { $Aprice=0; }

if ($FORM{'domain'} eq "yes") { $Bprice=30; }
else { $Bprice=0; }

if ($FORM{'host'} eq "yes") { $Gprice=25; }
else { $Gprice=0; }

if ($FORM{'hostplus'} eq "1") { $Hprice=10; }
elsif ($FORM{'hostplus'} eq "3") { $Hprice=30; }
elsif ($FORM{'hostplus'} eq "6") { $Hprice=60; }
elsif ($FORM{'hostplus'} eq "year") { $Hprice=120; }
else { $Hprice=0; }

if ($FORM{'nohost'} eq "yes") { $Iprice=40; }
else { $Iprice=0; }

if ($FORM{'nohostp'} eq "1") { $Jprice=30; }
elsif ($FORM{'nohostp'} eq "3") { $Jprice=90; }
elsif ($FORM{'nohostp'} eq "6") { $Jprice=180; }
elsif ($FORM{'nohostp'} eq "year") { $Jprice=360; }
else { $Jprice=0; }

$price=$Sprice + $Dprice + $Cprice + $Pprice + $Aprice + $Bprice + $Gprice + $Hprice + $Iprice + $Jprice;
}

# SEND MAIL
sub send_mail {
open (MAIL, "|$mailprog $recipient1") &#0124; &#0124; die "Can't open $mailprog!\n";
print MAIL "From:", (param('name')), , (param('email')),"\n";
print MAIL "To: TrinityDesigns\n";
print MAIL "Subject: Web Quote\n\n";
print MAIL "", (param('name'))," at ", (param('email'))," received a quote for a $FORM{'size'} web page with $FORM{'type'} and $FORM{'graph'} size(s) of graphics. This included promotion ($FORM{'promo'}) for ($FORM{'pplus'}) months, a domain name ($FORM{'domain'}), hosting under Trinity ($FORM{'host'}) for ($FORM{'hostplus'}) months. (If Trinity wasn't the host, then another host ($FORM{'nohost'}) was requested for ($FORM{'nohostp'}) months.\n\n";
print MAIL "This quote was for \$${'price'}.00.\n\n";
close (MAIL);
&confirmation;
exit;
}

# PRINT HTTP AND HTML HEADERS
sub print_header {
print header,
start_html("Web Quote"),
"<BODY BGCOLOR=\"Black\" BACKGROUND=\"http://trinitypages.com/web_page_pics/web_page_bg.jpg\" text=\"#0080C0\" ALINK=\"Black\" LINK=\"Teal\" VLINK=\"Purple\" BGPROPERTIES=\"FIXED\"><DIV ALIGN=\"center\"><IMG SRC=\"http://trinitypages.com/web_page_pics/web_page_ban12.gif\" WIDTH=600 HEIGHT=150 ALT=\"Web Quote\"<br><H1><FONT FACE=\"Comic Sans MS\" SIZE=\"+2\" COLOR=\"Yellow\"><BIG>WEB QUOTE</BIG></font></h1><br>\n";

}

# PRINT THE PERSONAL PAGE
sub print_personal {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>On the next few pages, you will be asked to answer some questions which will help us in arriving at an estimate for the web site you want. Your name and address are not required, but would be appreciated.</center></TD></TR></table><br><br>",
start_form,;
print "<table width=\"80%\"><TR><TD ALIGN=\"right\" VALIGN=\"top\"><FONT FACE=\"Comic Sans MS\" COLOR=\"#0080C0\">Name:</FONT><TD VALIGN=\"top\">",textfield(-name=>'name', -size=>'30', -value=>'Some One'),"</TR><TR><TD ALIGN=\"right\" VALIGN=\"middle\"><FONT FACE=\"Comic Sans MS\" COLOR=\"#0080C0\">Email Address:</FONT><TD VALIGN=\"top\">",textfield(-name=>'email', -size=>'30', -value=>'somebody@somewhere.com'),"</TR></table><br>";
print
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}

# PRINT THE SIZE PAGE
sub print_size {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>", (param('name')),","," here come the questions about what kind of web site you are thinking about. An average web site runs in the range of 5 to 9 pages, so it all depends on how you want your personal and/or business site to look.<br><br><br>Question #1: How many pages are you thinking about for your web site?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'size', -value=>' small (1 to 6 pages)'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'size', -value=>' medium (7 to 12 pages)'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'size', -value=>' large (12 plus pages)'),"<BR><BR></TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}


# PRINT THE ADDONS PAGE
sub print_addons {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>This question will help define the look of your pages.<br><br><br>Question #2: Which of the following would you like your pages to use?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'type', -value=>' None'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'type', -value=>' Frames'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'type', -value=>' Java'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'type', -value=>' Flash'),"<BR><BR></TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}

# PRINT THE GRAPHICS PAGE
sub print_graphics {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>Here's the really fun part for us ... GRAPHICS! We can create a wide variety of shapes, sizes and looks for you.<br><br><br>Question #3: What sizes of graphics are you interested in getting on your site?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'graph', -value=>' Small'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'graph', -value=>' Large'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'graph', -value=>' Both'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}

# PRINT THE DOMAIN PAGE
sub print_domain {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>This next question deals with how people will find you. There are three ways to do that .... have it hosted under someone (http://www.trinitypages.com/yourname ), (http://www.whoever.com/~yourname) or (http://www.yourname.com). The last is what is considered a domain name and is the preferred method especially for businesses.<br><br><br>Question #4: Did you want Trinity Designs to get you a domain name?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'domain', -value=>' Yes'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'domain', -value=>' No'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
hidden(-name=>'graph',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}


# PRINT THE HOST PAGE
sub print_host {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>This section deals with hosting your web site.<br><br><br>Question #5: Do you want Trinity Designs to host your web site?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'host', -value=>' Yes'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'host', -value=>' No'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
hidden(-name=>'graph',-value=>(param(''))),
hidden(-name=>'domain',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}

# PRINT THE HOSTPLUS PAGE
sub print_hostplus {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>Since Trinity will host you, we need to know how long.<br><br><br>Question #6: How long do you want Trinity Designs to host your site?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'hostplus', -value=>' 1 Month'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'hostplus', -value=>' 3 Months'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'hostplus', -value=>' 6 Months'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'hostplus', -value=>' Year'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
hidden(-name=>'graph',-value=>(param(''))),
hidden(-name=>'domain',-value=>(param(''))),
hidden(-name=>'host',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}

# PRINT THE NOHOST PAGE
sub print_nohost {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>This section deals with hosting your web site.<br><br><br>Question #7: Do you want Trinity Designs to find a host your web site?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'nohost', -value=>' Yes'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'nohost', -value=>' No'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
hidden(-name=>'graph',-value=>(param(''))),
hidden(-name=>'domain',-value=>(param(''))),
hidden(-name=>'host',-value=>(param(''))),
hidden(-name=>'hostplus',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}


# PRINT THE NOHOSTPLUS PAGE
sub print_nohostplus {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>Since Trinity is finding a host for you, we need to know how long.<br><br><br>Question #8: How long do you want hosting for?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'nohostp', -value=>' 1 Month'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'nohostp', -value=>' 3 Months'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'nohostp', -value=>' 6 Months'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'nohostp', -value=>' Year'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
hidden(-name=>'graph',-value=>(param(''))),
hidden(-name=>'domain',-value=>(param(''))),
hidden(-name=>'host',-value=>(param(''))),
hidden(-name=>'hostplus',-value=>(param(''))),
hidden(-name=>'nohost',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}


# PRINT THE PROMOTION PAGE
sub print_promotion {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>Since you want to have a site created you probably want people to see it! The first think would be to submit your site to search engines.<br><br><br>Question #9: Do you want Trinity Designs to promote your site for you?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'promo', -value=>' Yes'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'promo', -value=>' No'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
hidden(-name=>'graph',-value=>(param(''))),
hidden(-name=>'domain',-value=>(param(''))),
hidden(-name=>'host',-value=>(param(''))),
hidden(-name=>'hostplus',-value=>(param(''))),
hidden(-name=>'nohost',-value=>(param(''))),
hidden(-name=>'nohostp',-value=>(param(''))),
submit(-name=>'go',-value=>'On To Next Page'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}


# PRINT THE PPLUS PAGE
sub print_pplus {
my $current_page = shift;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><FONT COLOR=\"#0080C0\"><B>Since you chose to have promotion, we need to know how long you require our services.<br><br><br>Question #10: How long do you want the promotion (optimization)?</FONT></B><br><br>",
start_form,;
print "<TABLE width=\"80%\"><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'pplus', -value=>' 1 Month'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'pplus', -value=>' 3 Months'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b> ",radio_group(-name=>'pplus', -value=>' 6 Months'),"</TD></TR><TR><TD ALIGN=\"CENTER\"><b>",radio_group(-name=>'pplus', -value=>' Year'),"</TD></TR></table><br><CENTER>";
print hidden(-name=>'name',-value=>(param('name'))),
hidden(-name=>'email',-value=>(param('email'))),
hidden(-name=>'size',-value=>(param(''))),
hidden(-name=>'type',-value=>(param(''))),
hidden(-name=>'graph',-value=>(param(''))),
hidden(-name=>'domain',-value=>(param(''))),
hidden(-name=>'host',-value=>(param(''))),
hidden(-name=>'hostplus',-value=>(param(''))),
hidden(-name=>'nohost',-value=>(param(''))),
hidden(-name=>'nohostp',-value=>(param(''))),
hidden(-name=>'promo',-value=>(param(''))),
submit(-name=>'go',-value=>'Submit'),
hidden(-name=>'page',-value=>$current_page,-override=>1),
end_form;
}


# PRINT THE CONFIRMATION PAGE
sub print_confirmation {
start_form,;
print "<table width=\"80%\"><tr align=\"CENTER\"><td align=\"CENTER\"><FONT FACE=\"Comic Sans MS\" SIZE=\"+2\" COLOR=\"#0080C0\">\n";
print "", (param('name')),","," here is your ", (param('size'))," web site estimate:<br>\n";

print "<FONT SIZE=\"+3\">\$${'price'}.00</FONT></font></td></tr>\n";
print "</table>\n";
end_form;
}

# PRINT HTTP AND HTML FOOTERS
sub print_footer {
print footer
print "<p><br><br><br><HR WIDTH=\"90%\" ALIGN=\"CENTER\"><DIV ALIGN=\"center\"><FONT SIZE=\"-1\" FACE=\"Comic Sans MS\" COLOR=\"Silver\"><A HREF=\"http://trinitypages.com/index.html\">Home</A> |<A HREF=\"http://trinitypages.com/graphics.html\">Graphics</A> |<A HREF=\"http://trinitypages.com/prods.html\">Products</A> |<A HREF=\"http://trinitypages.com/pack.html\">Packages</A> |<A HREF=\"http://trinitypages.com/Lish/index.html\">Art</A> |<A HREF=\"http://trinitypages.com/guesstbook.html\">Guestbook</A> |<A HREF=\"mailto:trinity\@trinitypages.com\">Email</A></FONT></DIV><HR WIDTH=\"90%\" ALIGN=\"CENTER\"><br><br><P ALIGN=\"CENTER\"><FONT COLOR=\"Teal\" SIZE=\"-2\" FACE=\"Ariel\">Copyright \&copy; 1999, 2000\ <FONT SIZE=\"-1\"><B>Trinity Designs</B>\ <FONT SIZE=\"-2\">All Rights Reserved<br>All images on these pages are the property of Trinity Designs.<br>If you wish to use any of them, you need to contact us for <A HREF=\"mailto:trinity\@trinitypages.com\">permission</A></FONT></body></html>\n";

}
</pre><HR></BLOCKQUOTE>

Dreamer

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives