SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 6th, 2000, 04:01 PM
Givan Givan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 4 Givan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Givan
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

Reply With Quote
  #2  
Old July 6th, 2000, 09:53 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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;
}
}

Reply With Quote
  #3  
Old July 11th, 2000, 07:23 AM
Givan Givan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 4 Givan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Givan
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

Reply With Quote
  #4  
Old July 11th, 2000, 08:13 AM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 234 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 46 sec
Reputation Power: 9
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;

Reply With Quote
  #5  
Old July 11th, 2000, 06:47 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.


Reply With Quote
  #6  
Old July 12th, 2000, 06:19 PM
Givan Givan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 4 Givan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Givan
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

Reply With Quote
  #7  
Old July 12th, 2000, 07:35 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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/

Reply With Quote
  #8  
Old July 15th, 2000, 03:23 PM
ledjon
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.

Reply With Quote
  #9  
Old August 1st, 2000, 04:47 PM
Givan Givan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 4 Givan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Givan
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

Reply With Quote
  #10  
Old August 2nd, 2000, 12:27 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Data to a perl script from a html form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway