#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep 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.
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    #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.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    thanx dude, i will test this out.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    33
    Rep Power
    15
    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;
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep 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.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep 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.
  12. #7
  13. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>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

IMN logo majestic logo threadwatch logo seochat tools logo