The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Data to a perl script from a html form
Discuss Data to a perl script from a html form in the Perl Programming forum on Dev Shed. Data to a perl script from a html form Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 6th, 2000, 04:01 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
hello everybody
I have a question that might sound really stupid to al of you but I am just beginning with perl and I would like to know how to receive data in a perl script from a html form, with other words: how do I tell the script what to do with the information it gets from that form.
I guess this is as simple as anything but I hope someone will take a little time and give me that answer...
THANK YOU! URL
------------------
visit
www.gsm-plaza.com
|

July 6th, 2000, 09:53 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>how do I tell the script what to do with the information it gets from that form
Add a form parsing subroutine like below, then $FORM{'name'} or $FORM{'email'} will give you the value from <input type="text" name="name"> and <input type="text" name="email">
#!/usr/local/bin/perl
&parse_form;
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|n)*-->//g;
$value =~ s/<([^>]|n)*>//g;
$FORM{$name} = $value;
}
}
|

July 11th, 2000, 07:23 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
HI!
thanx to the information I got previously I made this simple guestbook but now I get the following error:
sh: +": bad option
sh: +": bad option
I don't know what it means and I don't know what to change so if anyone could help me???
thank you
#!/usr/local/bin/perl
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);
&parse_form;
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|n)*-->//g;
$value =~ s/<([^>]|n)*>//g;
$FORM{$name} = $value;
}
}
open (GUEST,"guest.html") | | die "Can't open guest.html!n";
@lines=<GUEST>;
close(GUEST);
$SIZE=@LINES;
open (GUEST,"guest.html") | | die "Can't open guest.html!n";
for ($i=0;$i<=$SIZE;$i++) {
$_=$LINES[$i];
if (/<!--begin-->/)
{
print GUEST "<!--begin-->";
}
print GUEST "<p>$FORM{'message'}<p>n";
print GUEST "<a href="mailto:$FORM{'email'}">$FORM{'name'}</a>$date<p>n";
print GUEST "<hr width=50%>n";
print GUEST $_;
}
close (GUEST);
------------------
visit
www.gsm-plaza.com
|

July 11th, 2000, 08:13 AM
|
 |
SwollenMember
|
|
Join Date: Jun 2000
Location: the master control
Posts: 264
Time spent in forums: 13 h 14 m 57 sec
Reputation Power: 14
|
|
|
Little less work if you want to use CGI:
#!/usr/local/bin/perl
use CGI;
my $cgi = new CGI;
$textbox = $cgi->param("entered");
$textbox =~ s/n/<br>/g;
$textbox =~ s/<|>//g;
print $cgi->header;
print "<br>";
print $textbox;
|

July 11th, 2000, 06:47 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
1) To write to guest.html, you need >>
open (GUEST,">>guest.html") | | die "Can't open guest.html!n";
for ($i=0;$i<=$SIZE;$i++) {
2) Make sure your script sends a successful page or redirects to the viewguest page.
3) $SIZE=@LINES;
needs to be $SIZE=@lines;
Try to download wwwboard and play with it.
|

July 12th, 2000, 06:19 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
hey, I changed what you said but it still won't work...
know anything else to change??
would help me a lot
thank you
------------------
visit:
- <A HREF="http://www.gsm-plaza.com
-" TARGET=_blank>www.gsm-plaza.com
-</A> givan.isfunky.com
|

July 12th, 2000, 07:35 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>know anything else to change??
Yes. Remove all the following lines or rewrite your script
$SIZE=@LINES;
open (GUEST,"guest.html") | | die "Can't open guest.html!n";
for ($i=0;$i<=$SIZE;$i++) {
$_=$LINES[$i];
As I mentioned, you should try wwwboard. Please go to http://www.worldwidemart.com/scripts/
|

July 15th, 2000, 03:23 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
I assume that the form you're sending the information from is using the POST method right? If it's using the GET method (or no method is specified) you'll need to use a different parsing routine.
I'm not going to bother going through your code to find a problem, just do as freebsd said and use one that's already made.
One more note: make sure guest.html is chmoded 777.
|

August 1st, 2000, 04:47 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thanks to all of you but I don't think I'll learn anything from just using someoneelses guestbook, it isn't about the guestbook, but about making such a programm myself
------------------
visit:
- <A HREF="http://www.gsm-plaza.com
-" TARGET=_blank>www.gsm-plaza.com
-</A> givan.isfunky.com
|

August 2nd, 2000, 12:27 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>it isn't about the guestbook, but about making such a programm myself
Yes, but not quite. The technique you are using..
if (/<!--begin-->/){
print GUEST "<!--begin-->";
is exactly the same as wwwboard. So I told you to check out wwwboard earlier and see how it works. Of course, if you are confidence enough, you can always write your own guestbook. On the other hand, if you are struggling with specific part of your script, you should immediately download wwwboard to get/steal some ideas.
>>I don't think I'll learn anything from just using someoneelses guestbook
Right, don't use the exact guestbook. Wrong, since you need to alter it and learn from it.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|