PDA

View Full Version : Submit Form CGI help


j_uu
10-27-2002, 10:09 PM
(PLEASE LET ME KNOW IF THIS ALTERATION IS CORRECT & WILL WORK ! :thumbsup: )


right, this is a long one !

my current submit form at :

http://www.handfinishedframes.com/contactus.html

uses this cgi code (it works fine) :





#!/usr/bin/perl5
# Read in form data
&parse_form;
&check_fields_ok;
&mail_admin;


sub mail_admin
{
#$to = "$in{'sendto'}";
$to = 'info@handfinishedframes.com';
$from = "$in{'email'}";
$subject = 'Hand Finished Frames Information Request Form';

print "Location: http://www.handfinishedframes.com/success.html \n\n";

open (MAIL, "|/usr/sbin/sendmail -t -n");
print MAIL <<ENDOFMAIL;
To: $to
From: $from
Subject: $subject

Name: $in{'name'}
Last Name: $in{'lastname'}
Title: $in{'title'}
Company: $in{'company'}
VAT NO (UK/EEC only): $in{'vat'}
Address: $in{'address'}
Town / City: $in{'town'}
County / state: $in{'county'}
Post / Zip Code: $in{'zip'}
Country: $in{'country'}
Telephone: $in{'telephone'}
Fax: $in{'fax'}
Email: $in{'email'}
Website: $in{'website'}
Comments: $in{'comments'}


ENDOFMAIL
close (MAIL);



#print "Location: http://www.handfinishedframes.com/success.html \n\n";
#print "Content-type: text/html\n\n";
#print "This is a test!";
exit;
}

sub check_fields_ok
{
if ($in{'name'} eq "" || $in{'email'} eq "")
{
print "Location: http://$ENV{'HTTP_HOST'}/error.html \n\n";
exit;
}
}


sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@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;
$in{$name} = $value;
}
}





my new submit form will be :

http://www.handfinishedframes.com/contactus-new.html

now, am i right in thinking that adding this new piece of code :

Newsletter: $in{'newsletter'}
Newsletter Format: $in{'newsletter-format'}

to the existing cgi script will work with the new checkboxes and radio buttons ?





new altered cgi script :





#!/usr/bin/perl5
# Read in form data
&parse_form;
&check_fields_ok;
&mail_admin;


sub mail_admin
{
#$to = "$in{'sendto'}";
$to = 'info@handfinishedframes.com';
$from = "$in{'email'}";
$subject = 'Hand Finished Frames Information Request Form';

print "Location: http://www.handfinishedframes.com/success.html \n\n";

open (MAIL, "|/usr/sbin/sendmail -t -n");
print MAIL <<ENDOFMAIL;
To: $to
From: $from
Subject: $subject

Name: $in{'name'}
Last Name: $in{'lastname'}
Title: $in{'title'}
Company: $in{'company'}
Address: $in{'address'}
Town / City: $in{'town'}
County / state: $in{'county'}
Post / Zip Code: $in{'zip'}
Country: $in{'country'}
Telephone: $in{'telephone'}
Fax: $in{'fax'}
Email: $in{'email'}
Website: $in{'website'}
VAT NO (UK/EEC only): $in{'vat'}
Newsletter: $in{'newsletter'}
Newsletter Format: $in{'newsletter-format'}
Comments: $in{'comments'}


ENDOFMAIL
close (MAIL);



#print "Location: http://www.handfinishedframes.com/success.html \n\n";
#print "Content-type: text/html\n\n";
#print "This is a test!";
exit;
}

sub check_fields_ok
{
if ($in{'name'} eq "" || $in{'email'} eq "")
{
print "Location: http://$ENV{'HTTP_HOST'}/error.html \n\n";
exit;
}
}


sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@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;
$in{$name} = $value;
}
}





if i am wrong, please let me know what needs to be added to make it work.

also, how long should it take to get this working on a server ?

thankyou very very much
jon

premshree
10-28-2002, 08:21 AM
I saw the form and I think it should work. Have you tried running it?

j_uu
10-28-2002, 02:13 PM
no, i haven't tried running it as our host doesn't allow me to use my own scripts and is charging me $75 to modify the code for my form and upload it which they say will take over an hour which i find hard to believe. so i am trying to work out what is required so i can tell them to go to hell and switch to another host.

thanks

jon

Mouldy_Goat
10-31-2002, 01:35 AM
$75 dollars?! You can get a good few years with a perfectly good CGI host which won't interfere and insist that it takes an hour to do a 30second script change.

In fact for that price you could probably find a host which offers PHP and MySQL thrown in. My host charges me £12/year, which works out at about $18 I think.. oh and they let me fiddle with my own scripts as and when I like via FTP.

I'd change if I were you..