Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help with cgi form

    Hi Peeps. I have a graded project working on. The project consists of a HTML form and two cgi scripts. The form will record a gift that the user selects. The user will be sent to the first cgi script where they will be prompted to enter shipping info. After user presses submit button, they will be taken to 2nd cgi script, where all info entered will be display. My problem is that when i select a radio button item, the first item in the group shows up and not the current selected item. Please if anyone can help i wud gladly appreciate it. I dont want to post my project online.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,916
    Thanks
    2
    Thanked 164 Times in 159 Posts
    You will need to post your code. Since this is for a course assignment, we won't be able to provide solutions, but we can give you pointers.

  • Users who have thanked FishMonger for this post:

    Sherby (06-06-2012)

  • #3
    New Coder
    Join Date
    Aug 2009
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Here are the codes.

    <!thomasjewelryonline.html>
    <HTML>
    <HEAD><TITLE>Thomas Jewelry Online</TITLE></HEAD>
    <BODY>
    <H1 ALIGN=center>Thomas Jewelry</H1><HR>

    <FORM METHOD="POST" ACTION="http://localhost/cgi-bin/new/script1.cgi">

    <P><B>Gift:</B></BR>
    <INPUT TYPE=radio NAME=Gift Value=Diamond Bracelet CHECKED> Diamond Bracelet<BR>
    <INPUT TYPE=radio NAME=Gift Value=Tennis Bracelet> Tennis Bracelet<BR>
    <INPUT TYPE=radio NAME=Gift Value=Diamond Earrings> Diamond Earrings<BR>
    <INPUT TYPE=radio NAME=Gift Value=Pearl Earrings> Pearl Earrings<BR>
    <INPUT TYPE=radio NAME=Gift Value=Onyx Ring> Onyx Ring</P>

    <P><INPUT TYPE=submit VALUE=Submit> <INPUT TYPE=reset></P>
    </FORM>
    </BODY>
    </HTML>



    This is the first script cgi script
    Note: You will need to include an array and a scalar variable for the radio group values.

    #!C:/Perl/bin/perl.exe
    #script1.cgi - contains a form that allows the user to enter form data
    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, $giftname);
    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');
    $giftname = param('Gift');

    print "<HTML>\n";
    print "<HEAD><TITLE>Thomas Jewelry Online</TITLE></HEAD>\n";
    print "<BODY>\n";
    print "<FORM ACTION='http://localhost/cgi-bin/new/script2.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 "<H1>Thomas Jewelry Online</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 SIZE=25></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></TD></TR>\n";
    print "</TABLE><BR>\n";
    print "<INPUT TYPE=submit VALUE=Submit>\n";
    print "</FORM></BODY></HTML>\n";



    This is the second cgi script
    Note: This script should display a web page that contains the customer name and address info and a list of the items that were ordered.

    Hint: You'll need to use a print scalar variable for the gift value.

    #!C:/Perl/bin/perl.exe
    #script2.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, $giftname);
    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');
    $giftname = param('Gift');

    #create Web page
    print "<HTML>\n";
    print "<HEAD><TITLE>Thomas Jewelry Online</TITLE></HEAD>\n";
    print "<BODY><H2>\n";
    print "<H1 ALIGN=center>Thomas Jewelry Online</H1><HR>\n";
    print "<B>Your shipping information is:</B><BR><BR>\n";
    print "$name<BR>\n";
    print "$street<BR>\n";
    print "$city<BR>\n";
    print "$state<BR>\n";
    print "$zip<BR><BR>\n";

    print "<B>List of items that were ordered:</B><BR><BR>\n";
    print "$giftname<BR>\n";


    print "</H2></BODY></HTML>\n";

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,916
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Why do you have these assignments and the corresponding hidden fields in script1 when the only param being sent to this script from the form is "Gift"?
    Code:
    $name = param('Name');
    $street = param('Street');
    $city = param('City');
    $state = param('State');
    $zip = param('Zip');

  • Users who have thanked FishMonger for this post:

    Sherby (06-07-2012)

  • #5
    New Coder
    Join Date
    Aug 2009
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have removed the hidden fields from the script and have included the following hidden fieldprint "<INPUT TYPE=hidden NAME=H_giftname VALUE='$gift'>\n"... . The instruction for script 1 is as follows:

    The script should contain a form that allows the user to enter his or her Name, street address, city, state and zip code.
    The form should include a hidden field to carry the information collected from the html document form onto script 2.
    Also an array and a scalar variable should be included for the radio group values.

  • #6
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CGI script

    Hi guys,
    I have started with CGI scripting in Perl and trying to run a cgi script as

    --------------------------------------------------------------------------
    #!/usr/bin/perl
    #cgihello.pl
    use strict;
    use warnings;

    print "Content-type: text/plain\n\n";
    print "Hello CGI World!\n";
    print "You're calling from $ENV{REMOTE_HOST}\n";

    which should give the output as
    Hello CGI World
    You're calling from 192.168.0.3
    --------------------------------------------------------------------------

    using IIS as the web server and it is mentioned in the ebook that I have to save the scripts in the Scripts folder of Inetpub in C drive.But there is no folder named Scripts in the Inetpub.

    The IIS is ON(Windows Vista).
    Please help me out of it.

  • #7
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,916
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Since this is an IIS issue, you'll get better answers from an IIS forum. It's been over 10 years since I used IIS, but I suspect that you need to manually create the directory.


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •