Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-04-2012, 11:25 PM   PM User | #1
Sherby
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Sherby is an unknown quantity at this point
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.
Sherby is offline   Reply With Quote
Old 06-05-2012, 12:39 AM   PM User | #2
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
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.
FishMonger is offline   Reply With Quote
Users who have thanked FishMonger for this post:
Sherby (06-06-2012)
Old 06-06-2012, 09:16 PM   PM User | #3
Sherby
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Sherby is an unknown quantity at this point
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";
Sherby is offline   Reply With Quote
Old 06-06-2012, 09:34 PM   PM User | #4
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
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');
FishMonger is offline   Reply With Quote
Users who have thanked FishMonger for this post:
Sherby (06-07-2012)
Old 06-07-2012, 10:48 PM   PM User | #5
Sherby
New Coder

 
Join Date: Aug 2009
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Sherby is an unknown quantity at this point
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.
Sherby is offline   Reply With Quote
Old 06-12-2012, 07:56 PM   PM User | #6
sanjila007
New to the CF scene

 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sanjila007 is an unknown quantity at this point
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.
sanjila007 is offline   Reply With Quote
Old 06-12-2012, 08:55 PM   PM User | #7
FishMonger
Super Moderator


 
Join Date: May 2005
Location: Southern tip of Silicon Valley
Posts: 2,753
Thanks: 2
Thanked 149 Times in 144 Posts
FishMonger will become famous soon enoughFishMonger will become famous soon enough
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.
FishMonger is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:54 PM.


Advertisement
Log in to turn off these ads.