View Full Version : An easy form handler
campbemr
01-30-2003, 03:46 AM
All I want is a code that can accept an input from a html form and ammend those inputs to a data file. Below is the code that I am using to accept the inputs.
#!/usr/bin/perl
print "Content-type:text/html\n\n";
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;
$FORM{$name} = $value;
}
print "<html><head><title>Form Output</title></head><body>";
print "<h2>Results from FORM post</h2>\n";
foreach $key (keys(%FORM)) {
print "$key = $FORM{$key}<br>";
}
print "</body></html>";
what else would i need to add to open the data file and print the inputs into that file. If I need to post the html that I am using also I will do that.
campbemr
01-30-2003, 03:48 AM
Also I am having trouble finding a free host were I could test these files. Could anyone recommend me to a good host.
Insomnia
02-13-2003, 06:55 AM
As for the latter, there are free hosts that allow CGI, including writing to files. I can't remember the entire list now, but here are a couple:
http://www.netfirms.com/
They put a banner on top of every page and block sendmail after a few posts.
http://www.portland.co.uk/
No ads. No sendmail. Only 100 MB monthly data transfer, which is enough if you only want to test the scripts.
http://www.ish.biz/
I haven't tried them yet, so I'm not sure how they handle writing to files, but I hear they are excellent for a free host. I think they place some link-back button on the buttom of your page. No sendmail.
As you can see, the real problem is finding a host that doesn't ban sendmail. I haven't found one yet.
As for the code, try this link:
http://www.cgi101.com/
Click on 'online class':
http://www.cgi101.com/class/
It deals also with reading and writing data file.
benastan
02-17-2003, 04:00 AM
i use tripod, it works great, but you have to have the right script to go along with it
http://www.tripod.com
i have created a script with multiple functions which make it millions of times ezer to get info from forms and links.
the first is the param() function.
if an input's name is "monkey" (<input type="text" name="monkey">)
then to get the value you simply write
$monkey = param('monkey');
it is really simple!
next is the cookie() function.
it is used for getting data from a cookie.
if a cookie is set to:
print "Set-Cookie:monkey=$monkey\n";
then you get the value by writing:
$monkey = cookie('monkey');
simple, right.
it also has header and footer and error functions, but i wont go into those for now.
to get this, goto
http://benastan.tripod.com/cgi-bin/ben.lib
view the source, take out the stupid pop up add script, and save it as "ben.lib" (plz i spent alot of time making it!!!).
its really helpful for me
if it doesnt help you, well, then ive wasted my time
either way, its ok...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.