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: Perl Programming Help: Intermediate:
Need to accept values from a form and write them to a file

 



abockover
Deleted

Jul 3, 2000, 5:26 AM

Post #1 of 7 (2010 views)
Need to accept values from a form and write them to a file Can't Post

I am writing a banner rotation program for my website and am tired of manualy adding banners to the data file.
Each line in the data file looks like this:

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

http://thelink.com|http://thebanner.com/banner.gif|http://textlink|This]http://thelink.com|http://thebanner.com/banner.gif|http://textlink|This is your text
</pre><HR></BLOCKQUOTE>

The program places the values in the data file into the html code.

the html code before output looks like:

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


<center>
<a href="$banner[0]">$banner[1]</a><br>
<a href="$banner[2]">$banner[3]</a>
</center>
</pre><HR></BLOCKQUOTE>

Now, Here is what i am having trouble doing:

I want to type in the variables for the data file in a form. When it is submitted, the data gets sent to the data file.


Help

Thanks,

Aaron

[This message has been edited by abockover (edited 07-03-2000).]


perlkid
stranger

Jul 3, 2000, 12:14 PM

Post #2 of 7 (2010 views)
Re: Need to accept values from a form and write them to a file [In reply to] Can't Post

 Use This At the top of your script

########################################
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@cgiPairs = split(/&/,$buffer);
foreach $cgiPair (@cgiPairs)
{
($name,$value) = split(/=/,$cgiPair);
$value =~ s/\+/ /g;
$value =~ s/%(..)/pack("c",hex($1))/ge;
$form{$name} .= "\0" if (defined($form{$name}));
$form{$name} .= "$value";
}
########################################

This code stores the form values into $form{'value'}.

Now name your forms. For the banner source I'd name the form "bsource". Then the value is stored into $form{'bsource'}. Make sure you point the form action to your script also.

Now open the data file.

open(DB, ">>/full/path/to/file.db");
print DB "$form{'burl'}|$form{'bsource'}|so on|and so on|";
close(DB);

The >> means to append (write to the end of the file), you can also use > to overwrite and < to simply read only.

That's it.

perlkid

[This message has been edited by perlkid (edited 07-03-2000).]


abockover
Deleted

Jul 3, 2000, 2:11 PM

Post #3 of 7 (2010 views)
Re: Need to accept values from a form and write them to a file [In reply to] Can't Post

Thank you so much perlkid, it works like a charm.

-Aaron


abockover
Deleted

Jul 3, 2000, 2:54 PM

Post #4 of 7 (2010 views)
Re: Need to accept values from a form and write them to a file [In reply to] Can't Post

Wow


Cure
User

Jul 3, 2000, 9:25 PM

Post #5 of 7 (2010 views)
Re: Need to accept values from a form and write them to a file [In reply to] Can't Post

perldoc CGI


Cure
User

Jul 3, 2000, 9:26 PM

Post #6 of 7 (2010 views)
Re: Need to accept values from a form and write them to a file [In reply to] Can't Post

CGI.pm is a module that comes standard with perl5 for getting data from html forms. CGI.pm is one of the only ways to parse cgi data correctly. Don't debate it, just use it!! View documentation at http://search.cpan.org/doc/GBARR/perl5.005_03/lib/CGI.pm


perlkid
stranger

Jul 3, 2000, 11:06 PM

Post #7 of 7 (2010 views)
Re: Need to accept values from a form and write them to a file [In reply to] Can't Post

 
No problem Abockover,

perlkid

 
 


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

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