CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Form to file program

 



siceman105
Deleted

Jul 26, 2000, 5:33 AM

Post #1 of 12 (3669 views)
Form to file program Can't Post

Please help!
I need a program that takes input from a form and writes it to a text file. Thing is I want the contents of the text file overwritten completely each time. So that only the last thing submitted is every shown in the file.

Anyone help please?


Kanji
User / Moderator

Jul 26, 2000, 6:32 AM

Post #2 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

With very little in the way of error or sanity checking ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl -w

use CGI qw/ :standard /;
use CGI::Carp qw/ fatalsToBrowser /;

my $file = "/tmp/file.mine";

print header;

if ( param('content') ) { open FILE, "> $file" or die "Can't open $file: $!";
print FILE param('content');
close FILE;

print "File overwritten ...", hr;
} elsif ( param ) {
print "Nothing to write ...", hr;
}

print start_form,
textarea( -name => 'content',
-force => 1, -default => "",
-rows => 10, -cols => 60 ),
submit( -value => 'Overwrite' ),
end_form;</pre><HR></BLOCKQUOTE>


siceman105
Deleted

Jul 26, 2000, 11:35 AM

Post #3 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

Hi, I tried to run the program and got the following error message:

Execution of run.cgi aborted due to compilation errors.

Please help!

Thanks

Sice


Kanji
User / Moderator

Jul 26, 2000, 11:44 AM

Post #4 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

And the compilation problems were...?


Cretep
User

Jul 26, 2000, 5:19 PM

Post #5 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

Try using the full path to the file not the relative path so it would look like /server/siceman105/html/cgi-bin/stuff.txt


siceman105
Deleted

Jul 27, 2000, 2:56 PM

Post #6 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

where would I look for this info? Im kinda inexperienced!

The script is at
http://questserver.hypermart.net/secure/cgi-bin/maintain/run.cgi

Thanks

Sice


mike
User

Jul 27, 2000, 3:07 PM

Post #7 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

Hello,

There are a lot of programs in the perlarchive that can do this for you. You can modify a few to look how you want too. But anyway what exactly was the complication error?


- Mike

------------------


siceman105
Deleted

Jul 28, 2000, 12:12 AM

Post #8 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

yeah I know there are some programs that take input from a form and write it to a file, but I need one that makes sure its a complete overwrite.

As for the error, I have no idea, thats the message that came up, never seen a message like that before, usually its an Error 500, but not with this script!


Cretep
User

Jul 28, 2000, 12:58 AM

Post #9 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

Well your host should have this info on ther FAQ or ask tech support. This may be a dumb question but is the script chmod 755?


randor
User

Jul 28, 2000, 9:44 AM

Post #10 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

try this one:

make a form with the following fields:
NAME
ADDRESS
PHONE

and send the form to the script.

#!/usr/bin/perl


$file = 'test.txt';


&get_form_data; # parse arguments from post
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
$ARGV[0] =~ s/\W//g;

sub get_form_data {
$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
@a = split(/=/,$pair);
$name=$a[0];
$value=$a[1];
$value =~ s/\+/ /g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$value =~ s/[\n\r]/ /sg; #remove \n
$value =~ s/\[\]//g; #remove []
push (@data,$name);
push (@data, $value);
}
%form=@data;
%form;
}

&error("$file") unless (open FILE, ">$file");
print FILE "$form{'NAME'}\n$form{'ADDRESS'}\n$form{'PHONE'}\n";
close FILE;

sub error {
print "Content-type: text/html\n\n";
print "An Error occured in the $_\n";
}


this will replace the file each time, to edit from this just replace the part of each $form{'HERE'} to suit your form.

hope this helps.



siceman105
Deleted

Jul 31, 2000, 12:29 AM

Post #11 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

Hi, I tried this, but I keep getting Error 500, saying that the script has a premature end to its headers!

I made sure I chmoded to 755!

What could the prob be?

Thanks

Sice


Kanji
User / Moderator

Jul 31, 2000, 8:17 AM

Post #12 of 12 (3669 views)
Re: Form to file program [In reply to] Can't Post

The error that's displayed on the page itself is useless: you need to look in your server's log(s) if you want anything remotely helpful.

If you don't have that capability, ask the server's administrators or help staff to do so for you.

More than likely, its something extremely stupid like a wrong path to perl or you uploading the CGI in binary format rather than ASCII.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives