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:
Input data of a html-form is lost

 



Sharkking
Deleted

Aug 27, 2000, 11:51 PM

Post #1 of 8 (1176 views)
Input data of a html-form is lost Can't Post

I´ve made a simple perlscript to realize a Guestbook, but the Data from the Form will not appear in the outfile. Maybe i got the wrong variables? I hope someone could help me.
Here´s a part of the script
HTML-File:
<form method="GET" action="/cgi-bin/gbook.pl">
INPUT NAME="rating" TYPE="RADIO" ALIGN=left VALUE="Sehr gut">Sehr gut<br>

PL-FILE:
print "<li>Beurteilung: <b>$in{'rating'}</b> \n";

after proceeding the values are not shown.
What did i do wrong ?



perlkid
stranger

Aug 27, 2000, 10:05 PM

Post #2 of 8 (1176 views)
Re: Input data of a html-form is lost [In reply to] Can't Post

 I'll email you the same thing too. So wich ever one you see first.

I'll take these three lines and tell you what is wrong with them, then you'll be able to print to your file.

1. $outfile = ">> /http/main/gbook.html";
2. open(OUTFILE, $outfile);
3. print OUTFILE "

Your definatly on the right track here.

but in 1. when you define $outfile you don't put the >> or > or < in there, just the full path. And I see a space after the >> you'd want to take that out.

In 2. You always need the >> or < or >. And around $outfile you still need the "" even though there already in the definition of $outfile.

3. This one is ok, but I have a tip.
Instead of using print OUTFILE "whatever";
try using qq~~; when ever you have more than one line. qq is good for printing html that has more than one line and contains " in the html. If you use qq you don't have to do this (\") to ("). You can leave them alone. But when using qq the caracters you use to handle the lines your going to print must not be in the lines. Just like print ""; You can't have a " in the lines or html your printing without escaping them. so when you use print qq~<html>~; You know that you can't have another ~ in the html without escaping it. You can use other characters instead of ~. Like a |. What ever you want.

After that, you would wind up with this for lines 1. 2. and 3.

1. $outfile = "/http/main/gbook.html";
2. open(OUTFILE, ">>$outfile");
3. print OUTFILE qq~
<html><a href="No Prob With These">I can use quotes</a>
~;
close(OUTFILE);

Also the books always use OUTFILE as a file handle but you can use any word you want in place of OUTFILE. I usually use db, or data.

perlkid

[This message has been edited by perlkid (edited 08-28-2000).]


perlkid
stranger

Aug 28, 2000, 1:05 AM

Post #3 of 8 (1177 views)
Re: Input data of a html-form is lost [In reply to] Can't Post

Hello Sharkking,

Welcome To The Forum.

I think That your code to print to a data base is a bit off. I don't know if your only posting fragments of your code and that's why but any way here is a piece of code that will work.

If the name of the form field, or radio button, or check box is rating than that will be your variable to work with. You've got that part down, Now,

You Open our data base,

open(db, ">/path/to/file.db");

db is the file handle, while you have to file open if you want to print to the file you have to put db in front of the "". Like so,

print db "<li>Beurteilung: <b>$in{'rating'}</b> \n";

and then if your finished you close the data base.

close(db);

That's it.

I posted that because in your line of code

print "<li>Beurteilung: <b>$in{'rating'}</b> \n";

I didn't see any file handle. That's why.

The rest looked right.

If you still have problems then check your permissions to make sure that the file your printing to is set to 777 and the folder containing the file is set to 773 at least. 777 is not a good idea for folders, people can see the contents of a folder through the browser if the folder has a permission greater than 773.

Good Luck Sharkking,

I want to learn German sometime,

perlkid

[This message has been edited by perlkid (edited 08-28-2000).]


Sharkking
Deleted

Aug 28, 2000, 1:29 AM

Post #4 of 8 (1176 views)
Re: Input data of a html-form is lost [In reply to] Can't Post

I´m not shure about this so i will post the code i got:

$outfile = ">> /http/main/gbook.html";
open(OUTFILE, $outfile);
print OUTFILE "

<hr>
<b>$in{'username'}</b> (eMail: <a href=mailto:$in{'email'}>$in{'email'}</a> )
aus <b>\"$in{'herkunft'}\"</b> das folgende ins Gästebuch.<p>

<li>Ich finde diese Seite <b>\"$in{'rating'}\"</b>.
</ul>
Sonstiger Senf:<br>
\"<b>$in{'comments'}</b>\"

";
close(OUTFILE);

You can see the book (not)working under http://www.pleite.org/form.html and the result-page under ../gbook.html


Sharkking
Deleted

Aug 29, 2000, 3:05 AM

Post #5 of 8 (1176 views)
Re: Input data of a html-form is lost [In reply to] Can't Post

Now i´ve done this, but i got a Internal Server error.

Heres The script:

#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<head><title>Neueintrag in das Gästebuch</title></head>\n";
print "<body>\n";
print "<center>\n";
print "<H2>Neueintrag in das Gästebuch</H2>\n";
print "<HR>\n";
print "</center><p>\n";
print "Wir haben von Ihnen folgende Angaben erhalten:<p> \n";
print "<ul> \n";
print "<li>Von: <b>$in{'username'}</b> \n";
print "<li>eMail: <b>$in{'email'}</b> \n";
print "<li>aus: <b>$in{'herkunft'}</b> \n";
print "<li>Beurteilung: <b>$in{'rating'}</b> \n";
print "<li>Sonstiger Kommentar:<br> \n";
print "<b>$in{'comments'}</b> \n";
print "</ul><p> \n";
print "<B>Vielen Dank für Ihre Eintragung in unser Gästebuch!</B><p> \n";
print "</BODY>\n";
print "</HTML>\n";

$outfile = "/http/main/gbook.html";
open(OUTFILE,">>$outfile");
print OUTFILE qq~ "
<hr>
<b>$in{'username'}</b><br>
(eMail: <a href="mailto:$in{'email'}">$in{'email'}</a> )
aus <b>$in{'herkunft'}</b>
<p>
<li>Ich finde diese Seite <b>$in{'rating'}\"</b><br>
Kommentar:<br>
<b>$in{'comments'}</b>
";
close(OUTFILE);

-------------------------------------------

Heres the HTML-Form:
<HTML>
<BODY bgcolor=#000000 text=#FFFF00 >
<H2>Gästebuchformular</H2>
<HR>

<form method="GET" action="/cgi-bin/gbook.pl">
Bitte hier den Namen eingeben: <INPUT NAME="username" TYPE="TEXT" COLS=30 SIZE="30" ALIGN=left><br>
Bitte hier die Email eingeben: <INPUT NAME="email" TYPE="TEXT" COLS=30 ALIGN=left><br>
Aus welcher Stadt: <INPUT NAME=herkunft" TYPE="TEXT" SIZE="50"><br>

<p>Wie beurteilst Du die Page ?</p>
<INPUT NAME="rating" TYPE="RADIO" ALIGN=left VALUE="Sehr gut">Sehr gut<br>
<INPUT NAME="rating" TYPE="RADIO" ALIGN=left VALUE="Gut">Gut<br>
<INPUT NAME="rating" TYPE="RADIO" ALIGN=left VALUE="Ganz ok">Ganz ok<br>
<INPUT NAME="rating" TYPE="RADIO" ALIGN=left VALUE="Verbesserungswürdig">Verbesserunswürdig<br>
<INPUT NAME="rating" TYPE="RADIO" ALIGN=left VALUE="Langweilig">Langweilig<br>
<INPUT NAME="rating" TYPE="RADIO" ALIGN=left VALUE="Scheisse">Scheisse<br>
<p>

Zum schluss noch ein eigener Kommentar:<p>
<TEXTAREA NAME="comments" ROWS=8 COLS=60 ALIGN=left></TEXTAREA>
<p>

<INPUT TYPE="SUBMIT" VALUE="Senden">

</BODY>
</HTML>


----------------
whats wrong with it ?


Sharkking
Deleted

Aug 30, 2000, 4:25 AM

Post #6 of 8 (1176 views)
Re: Input data of a html-form is lost [In reply to] Can't Post

HEYA .. it works Smile)

lot of thanx to you scriptkid . I think i have to learn much more about parsing :-))

You can visit the book working on http://www.pleite.org

I hope we stay in contact per mail (if my PC @home will work Smile)


perlkid
stranger

Aug 30, 2000, 10:38 AM

Post #7 of 8 (1176 views)
Re: Input data of a html-form is lost [In reply to] Can't Post

 Hi Sharkking,

Here,
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


OUTFILE qq~ "
<hr>
<b>$in{'username'}</b><br>
(eMail: <a href="mailto:$in{'email'}">$in{'email'}</a> )
aus <b>$in{'herkunft'}</b>
<p>
<li>Ich finde diese Seite <b>$in{'rating'}\"</b><br>
Kommentar:<br>
<b>$in{'comments'}</b>
";
close(OUTFILE);
</pre><HR></BLOCKQUOTE>

You don't use any quotes (") when you use qq

When You are using qq you are replacing the ""; with what ever you want. Not "

so instead of

OUTFILE qq~ "
";
close(OUTFILE);

do

OUTFILE qq~
~;
close(OUTFILE);

Notice that where you would have the " you have ~. Completly replaced.

Also,

If that is your whole program you missing the code that will parse the form and url values and store them into %in.

If you need it, (From your post of code you do) here is the code.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#############################################
sub parse_form {
my (@pairs, %in);
my ($buffer, $pair, $name, $value);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
&cgierr('You cant run this script from telnet/shell.');
}

PAIR: foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

($value eq "---") and next PAIR;
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);
}
return %in;
}


#############################################
%in =&parse_form;
</pre><HR></BLOCKQUOTE>

perlkid Smile

[This message has been edited by perlkid (edited 08-30-2000).]


perlkid
stranger

Aug 30, 2000, 11:00 AM

Post #8 of 8 (1176 views)
Re: Input data of a html-form is lost [In reply to] Can't Post

 
Great,

I allready Signed It, German Is Hard To Read, he he.

I sort of caught on though.

Well keep in touch.

But when I was all done and a had submited everything to your guest book,

The link back to home was targeted wrong, try useing this in the link,

<a href="http://www.pleite.org/" target="_parent">Home</a>

-K-,

See Ya,

And My Email address has changed Too.

Just See My Profile.

Perlkid Smile

 
 


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

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