Gossamer Forum
Home : General : Perl Programming :

cgi application

Quote Reply
cgi application
Hi
I want to intercept a form content, how do I call this in my perl script ?

that is my html page(the form itself)
<HTML>
<HEAD>
<TITLE>First CGI </TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>

<BODY bgcolor="#CC33CC" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<P align="center"><B>What is the number you want to see ?</B></P>
<FORM method="post" action="http://www.Inetwork.com/cgi-bin/cgi.pl" name="Marie">
<DIV align="center">
<INPUT type="text" name="textfield">
<INPUT type="submit" name="Submit" value="Submit">
</DIV>
</FORM>
<P> </P>
</BODY>
</HTML>

what should I write ,if for exemple, I want to print what have been wrote in the form to a data base ?

Thanks a lot ! Smile
Quote Reply
Re: cgi application In reply to
To get the input and save it to a file is simple...

Code:
#!/usr/bin/perl

use CGI;
my $in = new CGI;
use CGI::Carp qw/fatalsToBrowser/;

&process;
sub process {
open OUTPUT, ">>$pathtolog" or die "Unable to open transaction log.\n";
print OUTPUT $in ->param('textfield'), "\n";
close(OUTPUT);

print $in ->header('text/html');
print "$in ->param('textfield') was added.";
}

The code looks pretty right to me, there may be some errors in there cause I was in a rush :P



------------------
Michael Bray
....
Review your webhost, or find a new one at http://www.webhostarea.com


Quote Reply
Re: cgi application In reply to
Hello Michael

I know its simple to you what Federation asked.. I do have a follow up question.. if i had several fields in my html form and want to save it to a database do i need to add more

print OUTPUT $in ->param('textfield'), "\n";

into your code?

I'm new to this html form to cgi

thanks