Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #1  
Old June 13th, 2000, 02:38 AM
venom venom is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 4 venom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old June 13th, 2000, 03:11 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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.

Reply With Quote
  #3  
Old June 13th, 2000, 03:16 AM
venom venom is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 4 venom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanx dude, i will test this out.

Reply With Quote
  #4  
Old June 13th, 2000, 03:45 AM
Imo Imo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 33 Imo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;

Reply With Quote
  #5  
Old June 13th, 2000, 04:09 AM
venom venom is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 4 venom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old June 13th, 2000, 04:11 AM
venom venom is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 4 venom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #7  
Old June 13th, 2000, 04:49 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > newbie need help!

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap