The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
newbie need help!
Discuss newbie need help! in the Perl Programming forum on Dev Shed. newbie need help! 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:
|
|
|

June 13th, 2000, 02:38 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
i'm new in perl programming, can u guys help me on how can i pass the data from html form into txt file.
|

June 13th, 2000, 03:11 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
#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.
|

June 13th, 2000, 03:16 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
thanx dude, i will test this out.
|

June 13th, 2000, 03:45 AM
|
|
Contributing User
|
|
Join Date: Jul 1999
Posts: 33
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
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;
|

June 13th, 2000, 04:09 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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.
|

June 13th, 2000, 04:11 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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.
|

June 13th, 2000, 04:49 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>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
|
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
|
|
|
|
|