|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
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
|
|||
|
|||
|
i'm new in perl programming, can u guys help me on how can i pass the data from html form into txt file.
|
|
#2
|
|||
|
|||
|
#form.html
<html> <body> <form method="POST" action="/cgi-bin/script.pl"> <input type="text" name="username"><br> <input type="text" name="email"><br> <input type="submit" value="submit"> </form> </body> </html> ############################################ #script.pl #!/usr/local/bin/perl $log_file = "/path/to/log.txt"; &parse_form; &add_to_log; &thank_you; 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; } } sub add_to_log { open(LOG,">>$log_file"); print LOG "$FORM{'username'}|$FORM{'email'}n"; close(LOG); } sub thank_you { print "Content-type: text/htmlnn"; print "Thank You!"; exit; } ############################################ log.txt should have a format like this: (field delimited by "|" and each record delimited by a "n" newline) bob|bob@somewhere.com Please note this is just a quick example. You should check out http://www.scriptsearch.com/ and test/modify as many scripts as possible. |
|
#3
|
|||
|
|||
|
thanx dude, i will test this out.
|
|
#4
|
|||
|
|||
|
using freebsd's form.html:
#!/usr/local/bin/perl # script.pl # if you want to use the perl module. # i didn't test it but should work. use CGI qw(:standard); $log_file = "/path/to/log.txt"; open(OUTFILE,">>$log_file") or die; print OUTFILE param('username'),'|',param('email'),'n'; close(OUTFILE); print header, start_html('Thanks!'), h3('Thank you'), end_html; exit; |
|
#5
|
|||
|
|||
|
guys, it seems not working.. i've changed the path and chmod script.pl to 755 and log.txt to 777. i put all 3 files in cgi-bin and change $log_file = "log.txt"; and action="script.pl" in the form.html file.
|
|
#6
|
|||
|
|||
|
guys, it seems not working.. i've changed the path and chmod script.pl to 755 and log.txt to 777. i put all 3 files in cgi-bin and change $log_file = "log.txt"; and action="script.pl" in the form.html file.
|
|
#7
|
|||
|
|||
|
>>i put all 3 files in cgi-bin and change $log_file = "log.txt";
I don't know if you are testing this on your own web server or elsewhere. Anyway, you can try the following: 1) place form.html to your /home/username/public_html 2) place script.pl to /home/username/public_html/cgi-bin 3) place log.txt to /home/username/public_html/log 4) chmod log.txt to 666 and /log dir to 777 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > newbie need help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|