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

Hi, I'm new on Perlmonks, I have been trying to display a Web page that contains the customer's name and address information and the product that was ordered. I have tried everything and still not getting the product ordered on mystore2.cgi. Any suggestions? These are the codes I have so far: HTML:
<HTML> <HEAD><TITLE>My Store</TITLE></HEAD> <BODY> <H1 ALIGN=center>My Store</H1><HR> <FORM METHOD="POST" ACTION="/~xxxxx/cgi-bin/mystore1.cgi"> <P><B>Please select your gift from the following options</B><BR><BR> <INPUT TYPE=radio NAME=Gift Value=Diamond Bracelet CHECKED>Diamond Bra +celet<BR><BR> <INPUT TYPE=radio NAME=Gift Value=Tennis Bracelet> Tennis Bracelet<BR> +<BR> <INPUT TYPE=radio NAME=Gift Value=Diamond Earrings> Diamond Earrings<B +R><BR> <INPUT TYPE=radio NAME=Gift Value=Pearl Earrings> Pearl Earrings<BR><B +R> <INPUT TYPE=radio NAME=Gift Value=Onyx Ring> Onyx Ring</P><BR> <P><INPUT TYPE=submit VALUE=Submit> <INPUT TYPE=reset></P> </FORM> </BODY> </HTML>
MYSTORE1.CGI
#!usr/bin/perl #mystore1.cgi - contains a form that allows the user to enter form dat +a print "Content-type: text/html\n\n"; use CGI qw(:standard -debug); #prevent Perl from creating undeclared variables use strict; #declare variables my ($name, $street, $city, $state, $zip, $gift); my @gifts = ("Diamond Bracelet", "Tennis Bracelet", "Diamond Earrings" +, "Pearl Earrings", "Onyx Ring"); #assign input items to variables $name = param('Name'); $street = param('Street'); $city = param('City'); $state = param('State'); $zip = param('Zip'); $gift = param('Gift'); print "<HTML>\n"; print "<HEAD><TITLE>My Store</TITLE></HEAD>\n"; print "<BODY>\n"; print "<FORM ACTION='http://xxxxxxx/~xxxx/cgi-bin/mystore2.cgi' METHOD +=POST>\n"; print "<!hidden fields>\n"; print "<INPUT TYPE=hidden NAME=H_name VALUE='$name'>\n"; print "<INPUT TYPE=hidden NAME=H_street VALUE='$street'>\n"; print "<INPUT TYPE=hidden NAME=H_city VALUE='$city'>\n"; print "<INPUT TYPE=hidden NAME=H_state VALUE='$state'>\n"; print "<INPUT TYPE=hidden NAME=H_zip VALUE='$zip'>\n"; print "<INPUT TYPE=hidden NAME=H_gift VALUE='$gift'>\n"; print "<H1>My Store</H1><HR>\n"; print "<TABLE>\n"; print "<TR><TD>Name:</TD><TD><INPUT TYPE=text NAME=Name SIZE=25></TD>< +/TR>\n"; print "<TR><TD>Street Address:</TD><TD><INPUT TYPE=text NAME=Street SI +ZE=40></TD></TR>\n"; print "<TR><TD>City:</TD><TD><INPUT TYPE=text NAME=City SIZE=25></TD>< +/TR>\n"; print "<TR><TD>State:</TD><TD><INPUT TYPE=text NAME=State SIZE=25></TD +></TR>\n"; print "<TR><TD>ZIP Code:</TD><TD><INPUT TYPE=text NAME=Zip SIZE=25></T +D></TR>\n"; print "</TABLE><BR><BR>\n"; print "<INPUT TYPE=submit VALUE=Submit>\n"; print "</FORM></BODY></HTML>\n";
MYSTORE2.CGI
#!usr/bin/perl #mystore2.cgi - display Web page containing all information entered on + previous pages print "Content-type: text/html\n\n"; use CGI qw(:standard -debug); #prevent Perl from creating undeclared variables use strict; #declare variables my ($name, $street, $city, $state, $zip, $gift); my @gifts = ("Diamond Bracelet", "Tennis Bracelet", "Diamond Earrings" +, "Pearl Earrings", "Onyx Ring"); #assign input items to variables $name = param('Name'); $street = param('Street'); $city = param('City'); $state = param('State'); $zip = param('Zip'); $gift = param('Gift'); #create Web page print "<HTML>\n"; print "<HEAD><TITLE>My Store</TITLE></HEAD>\n"; print "<BODY><H2>\n"; print "<H1 ALIGN=center>My Store</H1><HR>\n"; print "<H3><B>You have entered:</H3></B><BR>\n"; print "<H4>$name<BR>\n"; print "$street<BR>\n"; print "$city<BR>\n"; print "$state<BR>\n"; print "$zip<BR><BR>\n"; print "<B>The Gift you ordered is:</B><BR>\n"; print "$gift<BR>\n"; print "</H4></BODY></HTML>\n";

Replies are listed 'Best First'.
Re: Calling a radio button to the second cgi script
by kcott (Archbishop) on Jun 12, 2012 at 02:30 UTC

    You have HTML code like:

    <INPUT TYPE=radio NAME=Gift Value=Diamond Bracelet CHECKED>Diamond Bra +celet<BR><BR>

    I suspect that not quoting attribute values is going to cause you problems. Does the attribute Value equal "Diamond", "Diamond Bracelet", "Diamond Bracelet CHECKED" or is it left unassigned due to silently ignoring a parsing error. Quoting the attribute values makes it absolutely clear, both to human readers and browsers alike, what the attribute value is.

    <INPUT TYPE="radio" NAME="Gift" Value="Diamond Bracelet" CHECKED>Diamo +nd Bracelet<BR><BR>

    Quoted attribute values are always allowed; under certain conditions, quoting is optional. I find it easier to simply quote all values and then no longer concern myself with this aspect of HTML markup syntax.

    Update: s/assigned/unassigned/

    -- Ken

      Per HTML5, this:

      <INPUT TYPE=radio NAME=Gift Value=Diamond Bracelet CHECKED>Diamond Bra +celet

      is exactly equivalent to this:

      <INPUT TYPE="radio" NAME="Gift" Value="Diamond" Bracelet="" CHECKED="" +>Diamond Bracelet
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Hi Ken, I was thinking about the same thing (that's what I was taught) but I realized that the codes in the textbook did not show that the values were in quotes.

        Suzie, it would have been useful if you'd identified the textbook or posted some relevant extract.

        Here's what the World Wide Web Consortium (W3C) has to say:

        ... In certain cases, authors may specify the value of an attribute without any quotation marks. ... We recommend using quotation marks even when it is possible to eliminate them. ...

        Extract from: 3.2.2 Attributes

        -- Ken

        If you can get access to the server logs you can see what's values are being sent to the server. You'll probably see what kcott suggested-- that the values being sent are just the first word of the value. When I copied your html with the radio buttons and viewed the source in a browser (Firefox), it interpreted the first word of each as the value and ignored the second.

      Thanks a bunch Ken, this proves that textbooks are not always correct :) Thumbs up to you.
        Sorry about that Anon. Monk
      Thanks a bunch Ken, this proves that textbooks are not always correct :) Thumbs up to you.
Re: Calling a radio button to the second cgi script
by Anonymous Monk on Jun 12, 2012 at 01:52 UTC
      Hi Anonymous Monk, the problem I am having is that the radio button selection from mystore.html is not displaying on the mystore2.cgi

        Hi Anonymous Monk, the problem I am having is that the radio button selection from mystore.html is not displaying on the mystore2.cgi

        You can see everything that gets sent to mystore2.cgi if you add a call to sub DebugCGI , that ought to be very illuminating :)

        Giving http://validator.w3.org/ a copy of mystore.html ought to be equally as enlightening :)

        Like the others mention, your form html is probably to blame, if you look at http://search.cpan.org/dist/CGI/MANIFEST you can see what kind of html CGI.pm's radio_group function generates -- the output can be a source of known-good html for you to copy/paste

        You should also call escapeHTML before printing those raw value you get from param()

Re: Calling a radio button to the second cgi script
by poj (Abbot) on Jun 12, 2012 at 07:41 UTC
    In mystore1.cgi you have the parameter name H_gift
    print "<INPUT TYPE=hidden NAME=H_gift VALUE='$gift'>\n";
    and in mystore2.cgi you have Gift
    $gift = param('Gift');

    They need to be the same.

    poj
      SuzieB i am doing the same project and i basically have the same codes as yours. I have included the hidden field for the gift value and i still have not gotten the gift to show on the web page. If u have figured it out i would love for you to enlighten me.
        As soon as I figure out what I am doing wrong, I will surely enlighten you.
        Ha ha problem solved!!!!