|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
>>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; } } |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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; |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
>>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/ |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
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 |
|
#10
|
|||
|
|||
|
>>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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Data to a perl script from a html form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|