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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need your help with saving form data to server

Status
Not open for further replies.

Cervantes

MIS
Apr 1, 2003
147
CA
Aren't the simplest questions always the hardest?

I'm setting up an intRAnet web page so the users can submit data to me. I'm hosting it off my work PC.

I have the form created, and the page loading fine. Now, what I need is for the form to save to a file (on my work PC, the "server"). Simple, eh?

But, for the life of me, I can find no help on how to do this... all the help I can find is on how to email forms, which doesn't work because we're Exchange here, and client-side email isn't configured right. The rest of the help I find is specific to *nix remote servers.

Can someone please set me on the right path?

[starting from the basics, please. HTML/CGI is not my strong suit] :)
 
Hi Rieekan;
Thanks for the link. I should have been clearer in my post, though. I don't actually want to email the form, but the only useful forms help I can find is on emailing. I want to save it as a text file, so that I can tie it into an existing VBA script I have that plugs account information into my master excel sheet.

That said, the FAQ is useful for when I open up my web server at home :)
Thanks!
-Cerv
 
Ok, so I've cobbled together something that might start resembling a form. However, I'm stuck getting a 404 when I click submit.

Here's the HTML:
Code:
<form method="POST" action="save.pl">
  <p><input type="checkbox" name="Invoice_Number" value="ON">Invoice Number</p>
  <p><input type="checkbox" name="Invoice_Date" value="ON">Invoice Date</p>
  <p><input type="submit" value="Submit" name="Submit"><input type="reset" value="Reset" name="Reset"></p>
</form>
And here's save.pl from my \cgi-bin:
Code:
#C:\\Perl
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/\r/ /g;
$buffer =~ s/\n/ /g;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
$first=$formdata{'Invoice_Number'};
$last=$formdata{'Invoice_Date'};

open(INFO, ">>ebilling.txt"); # Open for appending
print INFO "$last|$first\n";
close (INFO);

print "Content-type:text/html\n\n"; #Content Header
print <<End_of_Doc;
<html>
<head><title>Done!</title></head>
<body>
Thank you!
</body>
</html>
End_of_Doc

Any ideas why it doesn't like me?
 
I think most people here think Perl when they hear CGI, but let me ask first, do you have Perl installed on your machine? Or were you planning on using some other language? And also, will this be running on Windows?

Perl is one of your options for cgi, as are JSP's, ASP's, and PHP.

 
Aye, I have Perl installed, and I've run a Hello World cgi/pl test script to make sure it's working.

Machine is (no laughing now), WinXP Sp1, IIS5.1, and ActivePerl 5.6.1.
 
I'm not familiar with ActivePerl, but it looks like CGI.pm's installed by default, which is good. You'll need to take a look at the docs for cgi.pm, which you can find at cpan.org. Here's a direct link to the part of the docs that deals with getting parts of a form:
You'll need to have something like this at the top of your script:
Code:
use cgi;
my $query = new CGI;

You'll also need to look at some perl tutorials on how to open a file for writing. Here's some links to tutorials:
 
You'll need to provide the path name to 'save.pl'.

Code:
<form method="POST" action="c:/the_path_to/save.pl">

There's always a better way. The fun is trying to find it!
 
Very useful links, philote. Thanks!
I'm working through them now... I've set up a very simple script:
Code:
#!C:\\Perl
$sitedata="billing.txt";
open(DAT,">>$sitedata") || die("Cannot Open File");
print DAT "Testing123\n"; 
close(DAT);

However, when I run it, I get a CGI error on line 3 (the open). I've checked to make sure that the cgi-bin directory is read/write... any other ideas?

I appreciate all the help with what must be an annoying newb. :) I'd slog through it myself, but I've till thursday to get this g'dang thing up...

Any fantasic ideas greatly appreciated ;-)
Cerv
 
Hi tviman!
Well, adding the path certainly made things interesting. Now, when I try to view the page through IE 6.0, it asks me if I want to open or save the "save.pl" file. On the bright side, if I open, it does write the text file. Yay!

In Firefox 0.8, it pops up an alert saying "c is not a registered protocol."

Were those supposed to be forward- or back- slashes? I've tried it with both, same result.

I can sense the relentless momentum of progress... I just hope it doesn't run me over. :)
-Cerv
 
The 'action' should be the path to the script's url, such as
For the above script, are you running it from the command line or from a web page? That may make a difference in which directory your script is looking for that file in. You can always put in the complete path to the file and see if that helps.

Also, what exact error are you getting? If you're running it from a web page and not getting a specific error, try running it from the command line and see if you get any more detail as to what the problem is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top