You will need the form data field name which the text is being passed to. Then you must have a parsing routine to prep the data, then after parsed, retrieve the data, and store it to a variable. Open a text log file and write it to the file. Close the file, then print some output.
>> will add to data that is already in the log file, > will erase whatever is in the file being written to and replace with the new. I have created entire database with flat text files so I know this.
Heres the code, the parse routine is from the Visual quickstart guide which I store in a separate file named main.lib
create a cgi-file named write_text.cgi
Be sure that owner permission of write_text.cgi is set to execute or you will get an error.
write_text.cgi
#!/usr/bin/perl
require "../library/one.lib";
#Uses library where parse routine resides ../moves up one directory
&parse;
#parsing data subroutine
&mime;
#html output subroutine
$data_to_write = $formdata {'java_data'};
#pull data from form field sent by java, java_data is the variable containing java text to be written
open (DATALOG, ">>../log.text"

|| &errormes;
#open logfile for access
flock (DATALOG, 2);
#creates exclusive access to file
print DATALOG "$data_to_write";
#prints form data to file
flock (DATALOG, 8);
#release exclusive access of file
close (DATALOG);
#closes filehand
#print output for user to let know function performed successfully
print "<center>";
print "<hr size="100%" color="#990000";
print "DATA WRITTEN TO TEXT FILE SUCCESSFULLY!!";
print "<hr size="100%" color="#990000";
#END OF write_text.cgi
Here is the library file which you also need to create to parse your data to get it ready to print to the text file
Here is the code for your library file main.lib
sub parse {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
}
sub errormes {
print "<hr width=100% color=#000099 size=12 style='border:7px ridge #000099'>";
print "<HTML><HEAD><TITLE>error message</TITLE></HEAD><BODY BGCOLOR=#FFFFFF><CENTER><BR><BR>";
print "<TABLE BORDER=1 WIDTH=416 CELLSPACING=0>";
print "<TR><TD BGCOLOR=#000099 align=center>";
print "<FONT SIZE=5 COLOR=black<B>Unable to open or write to file</B></FONT></TD></TR></TABLE></BODY></HTML>";
exit;
}
sub mime {
print "Content-type: text/html\n\n";
}
1; #If return value is not set, library will not work!!
<i>Its okay to dream.....</i>