b310 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have a script where when a user clicks on the Checkout button you should be redirected to a secure connection and brought to a billing form. What's happening I'm being brought back to my main product category page.

Can someone take a look at my code and help me figure out why my billing page is not appearing when I'm in the secure connection?

Shouldn't this line, which is in the get_checkout_link sub,
return (a ({-href => $url. "?choice=checkout"},
pass me to my display_billing_form which is in the dispatch section of my code? It's not.

sub get_checkout_link { my $label = shift; my $url; ($url = "https://www.addr.com/~summitwe/cgi-bin/pet_shop.cgi") =~ +s/^http:/https:/i; return (a ({-href => $url. "?choice=checkout"}, img ({-src => "../ +images/checkout.jpg", -border => "0", escapeHTML ($label)}))); }

Dispatch section of code when user clicks Checkout button.
elsif ($choice eq "checkout") # customer is ready to check out { $page .= display_billing_form ($dbh, $cart_ref); }


Here's is the code for the billing form.
sub display_billing_form { my ($dbh, $cart_ref) = @_; my ($state_val_ref, $state_label_ref); my $page; my $JSCRIPT; if (!keys (%{$cart_ref})) { $page .= p ({-style=>"font-family: verdana; font-size: 10pt;"} +, "Shopping cart is empty."); return ($page); } # Get references to lists of state abbreviations # and names for state popup menu ($state_val_ref, $state_label_ref) = WebDB::get_lookup_values ( $dbh, "SELECT abbrev, name FROM us_state ORDER BY na +me"); $page .= format_checkout_html ($cart_ref, 1); $page .= p({ -style => "font-family: verdana; font-size: 10pt;" +}, "Shipping and tax may be added to your order.\n" . "To estimate shipping and tax, please see the " . span({-style => "text-decoration: underline; colo +r: blue; cursor: pointer;", -onClick => "launchwin()"}, "Shipping and Tax") . " page.\n"); $page .= start_form (-method => "POST", -action => url ()); $page .= table ({-align => "center", -valign=>"center", -style=>" +font-family: verdana; font-size: 10pt;"}, Tr ({- +bgcolor=>"blue", -style=>"font-family: verdana; font-size: 10pt; colo +r: yellow; font-weight: 700;"}, + td ({-colspan => "2"},"Customer Information") ), Tr ( td ("Name:"), td (textfield (-name => "cust_name", -size => "40" +)) ), Tr ( td ("Address:"), td (textfield (-name => "street", -size => "60")) ), Tr ( td ("City:"), td (textfield (-name => "city", -size => "60")) ), Tr ( td ("State:"), td (popup_menu (-name => "state", -values => $state_val_ref, -labels => $state_label_ref)) ), Tr ( td ("Zip code:"), td (textfield (-name => "zip", -size => "10")) ), Tr ( td ("Email address:"), td (textfield (-name => "cust_email", -size => "60 +")) ), Tr ( td ("Daytime Phone:"), td (textfield (-name => "cust_dayph", -size => "20 +")) ), Tr ( td ("Evening Phone:"), td (textfield (-name => "cust_evenph", -size => "2 +0")) ), Tr ({-bgcolor=>"blue", -style=>"font-family: v +erdana; font-size: 10pt; color: yellow; font-weight: 700;"}, td ({-colspan => "2"},"Shipping Informat +ion") ), Tr ( td ("Name:"), td (textfield (-name => "ship_name", -size => "40" +)) ), Tr ( td ("Address:"), td (textfield (-name => "ship_street", -size => "6 +0")) ), Tr ( td ("City:"), td (textfield (-name => "ship_city", -size => "60" +)) ), Tr ( td ("State:"), td (popup_menu (-name => "ship_state", -values => $state_val_ref, -labels => $state_label_ref)) ), Tr ( td ("Zip code:"), td (textfield (-name => "ship_zip", -size => "10") +) ), Tr ( td ("Email address:"), td (textfield (-name => "ship_email", -size => "60 +")) ), Tr ( td ("Daytime Phone:"), td (textfield (-name => "ship_dayph", -size => "20 +")) ), Tr ( td ("Evening Phone:"), td (textfield (-name => "ship_evenph", -size => "2 +0")) ), Tr ({-bgcolor=>"blue", -style=>"font-family: v +erdana; font-size: 10pt; color: yellow; font-weight: 700;"}, td ({-colspan => "2"},"Shipping Method") ), Tr ( td ("Please select a shipping method:"), td (popup_menu (-name => "method", -valu +es => ["ND", "23D", "NDD"], -labels => {"ND" => "Normal Delivery", "2 +3D" => "2-3 Day Delivery", "NDD" => "Next Day Delivery"})) ) ) . br () . submit (-name => "choice", -value => "proceed to checkou +t") . end_form (); return ($page); }

Thank you for all your help.

Replies are listed 'Best First'.
Re: Secure Connection Redirection problem
by zby (Vicar) on Mar 16, 2003 at 17:14 UTC
    You should definitely make this a bit simpler and cut out the nonimportant parts of the code to leave just what you think is the core of the error. This is a general modus operandi.

    With what you supported we can only gues what is the problem. Here is my gues: the $choice variable is not properly set - you know you need to set it explicitely, there is no autovivification of variables like in PHP?

      Hello Zby:

      Thanks for your response. My problem is solved. The variable $choice wasn't the issue. The problem was elsewhere which someone had caught.