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: Beginner:
Help with form output to html file

 



Nandy
Deleted

Aug 31, 2000, 7:27 PM

Post #1 of 4 (290 views)
Help with form output to html file Can't Post

Hello:
I have just started learning the basic of cgi programing using perl. I am using a form from a book and i am trying to make it work for my idea. This is an excersise i have decide to make. Originaly the form was made just to show how can one form be build on html and originaly on the book it have no script to use with it. So i decide to make the script and try to apply what i believe i have learn. Looks like i quite haven't get the idea since it is not working. What i need is somebody to point out my mistakes. I will post here both the form and the perl script. I just hope i don't crash the server... BTW i am running this on an Apache server on a RedHat 6.2 Linux server. I have run several other scripts already ranging from a very simple voting form to a guestbook and a shtml counter. So the server should be setup ok and not be the problem. Also all the files have executable permision and can be read by everyone...

Here is the form,i will omit the html and body from the beggining and the bottom just to try to avoid the form to be readed and post it as an html page... Before i forget, this is a server on an intranet, i have no dns name...
http://linux.quinonesfamily.com/survey.html


<head><title>A Survey Form</title></head>

<h1>A Survey Form</h1>

<form action="http://linux.quinonesfamily.com/cgi-bin/survey.pl" METHOD="post">
<P>Name:
<INPUT TYPE="text" NAME="name" SIZE=30 MAXSIZE=50>
</P>

<P>
<INPUT TYPE="checkbox" NAME="purchaser" VALUE="yes">
I am authorized to make purchases.
</P>

<P>
IT budget:<br>
<INPUT TYPE="radio" NAME="budget" VALUE="1000">Less than $10,000<br>
<INPUT TYPE="radio" NAME="budget" VALUE="100000">From $10,000 to $100,000<br>
<INPUT TYPE="radio" NAME="budget" VALUE="1000000">From $100,000 to$1,000,000<br>
</P>

<P>
Current job reponsibility:
<SELECT NAME="job" SIZE=1>
<OPTION VALUE="senior">Senior Management
<OPTION VALUE="management">Management
<OPTION VALUE="engineer">Engenieer
<OPTION VALUE="consultant">Consultant
</select>
</P>

<P>
Comments:<br>
<TEXTAREA NAME="comments" WRAP="virtual" COLS=40 ROWS=6></textarea>
</P>

<p>
<INPUT TYPE="submit">
<INPUT TYPE="reset">
</P>


This is the pearl file i am trying to make work. I just want it to generate a simple html output showing the choices made on the survey.html. All i am getting righ know is the text on the html but the choices wont show. I have omited the shebang for just in case..
http://linux.quinonesfamily.com/cgi-bin/survey.pl

#Impirt the cgi module and create a quieyt object to retrieve the
#form input
use CGI;
$query = new CGI;

#variables are:
#$name
#$purchaser
#$budget
#$job
#$comments

print $query->header;
print "<html><head><title>Survey Info</title></head><body>\n";
print "<h1>Survey Info</h1>\n";
print "<p>You are $name</p>\n";
print "<p>You answer $purchaser to the question if you can purchase.</p>\n";
print "<p>Your budget is around $budget</p>\n";
print "<p>The position you have in the company is $job</p>\n";
print "<p>This are your coments:</p>\n";
print "<p>$comments</p>\n";

print "</body></html>\n";


I will realy apreciate any help that can be provided. You don't need to tell me how to do it, although i wouldn't mind. But if you just point out the mistake i am doing i will try to find out the correct way looking over the documentation i have.

Thanks,
Nandy

[This message has been edited by Nandy (edited 08-31-2000).]


fashimpaur
User / Moderator

Sep 1, 2000, 5:30 AM

Post #2 of 4 (290 views)
Re: Help with form output to html file [In reply to] Can't Post

Okay, Nandy.

It looks pretty simple. You have one mistake in the perl script that I see off hand.

$query = new CGI; creates a new CGI object.

you are doing nothing with it though.

For each of your variables, you must get the
parameter value. Do this following this format...

$yourVarName = $query->param(formVarName);

This is long and tedious though, and if you
have differences in the namse used on the
form and names used in the script, it can get
very confusing. So, I recommend this:

my %p; # make a hash to store parameters
foreach my $key ($query->param){
$p{$key} = $query->param($key);
}

Now you have a hash with all the keys being
the names of your form element variables
exactly the way you entered them in your HTML
form. This ensures you use the same names
and dont get confused.

Lastly, once the script is on the web server,
since you are using a *nix server, make sure
you do a chmod 0755 on the perl script.

Hope this helps,

Dennis


Nandy
Deleted

Sep 1, 2000, 5:59 PM

Post #3 of 4 (290 views)
Re: Help with form output to html file [In reply to] Can't Post

It works!!! Thanks Denis!! So my mistake was not to specify the variables values on the perl file... I though they were no need since they where specify on the html form. Now i know better. Actually this excercise gave me a better feel at creating this file.

Thanks for your help once again...

Fernando Quinones


Cure
User

Sep 1, 2000, 6:28 PM

Post #4 of 4 (290 views)
Re: Help with form output to html file [In reply to] Can't Post

perldoc CGI


Cure

 
 


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

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