Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Form to Txt File

Status
Not open for further replies.

esearing

IS-IT--Management
Aug 22, 2000
132
US
My Website host does not support ASP which I normally use
to load data from a form to a text file. They do support pl
extension files.

Is there a simple method to pass my variables from
the form to the text file using Perl.
Please be precise in your answer, I know nothing about Perl.

Thanks in advance. eSearing.com
a work in progress
 
Yes.

#=================== Dump.cgi ===============
#!/usr/bin/perl

#The line above is necessary for most CGI scripts. Unless
#the server is configured to recognize the file extension
#as a perl script that needs to be executed, then this line
#will need to point to the locatoin that perl.exe resides.
#On unix systems, this is pretty standard. Windows and
#others, you'll have to find it. Your host should be able
#to tell you.

use CGI; #this is a module that your host should have.
use CGI::Carp qw(fatalsToBrowser);

my $j = new CGI;

my $file = "./file_name_here";
# Change this to whatever you want.

open(FILE, ">>$file");
print FILE "===== START =====\n";
print FILE scalar(localtime), "\n\n";
print FILE $j->Dump;
print FILE "===== END =====\n";
close(FILE);

#================= END FILE =======================


Hope this works, it's untested, but the logic is sound. Just remember to change the $file variable to something you need.

--Jim
 
How do I identify my variables values?
I have 2 Name and Comment.

Also does this append to the txt file or overwrite.
I need to append. eSearing.com
a work in progress
 
It will append.

I'm not quite sure what you mean by: I have 2 name and Comment.

But once this file is used by your script, you should view it in a browser, it should be nicely formatted with the 'variable' names and their values.

The Dump method will create a HTML formatted list with all the parameters passed to it by the form.

Did you try it?

--Jim
 
Not there yet.

I added the code to a file named addIdea.pl
changed the line indicated.

my $file = "addIdea.txt";
# Change this to whatever you want.
# the txt file is on the same path as the pl file

When I hit submit from my form, the addIdea.pl
code is displayed but does not write to the text file.
Below is my form action.

<form name=&quot;ideas&quot; method=&quot;get&quot; action=&quot;addIdea.pl&quot;>
eSearing.com
a work in progress
 
The code should not be displayed
It should execute...

Make sure that your webserver has the .pl extension associated with the perl executable
 
I finally moved my form, textfile, and the pl file above to
Hypermart.com which does allow CGI scripting.

I'm now getting an error &quot;Premature end of script&quot;.

Jim, can you debug? I'll send you a MCI PrePaid phone card if I can get this resolved. eSearing.com
a work in progress
 
FIRST make sure you are uploading your CGI files in ASCII mode (if you are using an FTP program).

That's a pretty common cause of this broad and vague error message.

Next, make sure permissions are set (if necessary) Your CGI file needs to be readable, and executable by everyone. Writable only by you. In UNIX permissions scheme, this equates to 755. (&quot;chmod 755 mycgi.cgi&quot; but that's only if it is a UNIX server and you can telnet to it... probably not the case w/ hypermart.)

I don't know what the path is to Perl on the Hypermart server, but make sure your path is correct (at the top of the script).

Lastly, make sure that your script is syntactically correct by testing on the command line:

perl -c scriptname.pl

This will check the syntax and report:
syntax OK
if nothing is amiss.

Hope this does it.

--Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top