# Form - cgi/perl

**URL:** https://forum.kirupa.com/t/form-cgi-perl/169863
**Category:** Uncategorized
**Created:** [November 20, 2005, 3:17pm UTC](https://forum.kirupa.com/t/form-cgi-perl/169863 "2005-11-20T15:17:46Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![yell\_sheep](https://avatars.discourse-cdn.com/v4/letter/y/f05b48/32.png) [@yell\_sheep](https://forum.kirupa.com/u/yell_sheep)
#### Post date: [November 20, 2005, 3:17pm UTC](https://forum.kirupa.com/t/form-cgi-perl/169863/1 "2005-11-20T15:17:46Z")

</div>

Hello all: I am very new at this whole process of creating a form, so I am having some trouble at getting my form to work properly. And not sure what my ISP needs for this to work, I’ve switched my hosting to CGI. Below is the form:

[http://www.medianomadz.com/estimateform.htm](http://www.medianomadz.com/estimateform.htm)

**[color=seagreen]And here is my estimate.pl code:[/color]**

#!/usr/bin/perl  
$mail\_prog = ‘/usr/sbin/sendmail’ ;  
use CGI ;  
$query = new CGI;  
@referers = (‘[medianomadz.com](http://medianomadz.com)’);

if ($ENV{‘HTTP\_REFERER’})  
{  
foreach $referer (@referers)  
{  
if ($ENV{‘HTTP\_REFERER’} =~ m|https?://([^/]\*)$referer|i)  
{  
$check\_valid = 1;  
last;  
}  
}  
if ($check\_valid == 1)  
{  
#start main  
if ($ENV{‘REQUEST\_METHOD’} eq ‘POST’)  
{  
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;  
$value =~ s/~!/ ~!/g;

# Uncomment for debugging purposes

# print “Setting $name to $value”;

if ($name eq “report”) {  
$report = $value;  
}  
else {  
$value =~ tr/’/~/;  
$param = join(’’, $param," ‘",$value,"’");  
}  
}

# 

# Get the values of each fields

# 

$name = $query-\>param(‘name’); # Name  
$company = $query-\>param(‘company’); # Company  
$title = $query-\>param(‘title’); # Title  
$address = $query-\>param(‘address’); # Address  
$address2 = $query-\>param(‘address2’); # Address2  
$city = $query-\>param(‘city’); # City  
$province = $query-\>param(‘province’); # Province  
$country = $query-\>param(‘country’); # Country  
$postal = $query-\>param(‘postal’); # Postal Code  
$phone = $query-\>param(‘phone’); # Phone  
$fax = $query-\>param(‘fax’); # Fax  
$email = $query-\>param(‘email’); # E-Mail  
$comment = $query-\>param(‘comment’); # Comments  
$promo = $query-\>param(‘promo’); # Promo

#######  
#Grabs the date & time to be use for Confirmation  
#######  
$abc = `date '+%m%d%y%H%M'`;

#############################

# Client Request Email

#############################  
open (MAIL, “|$mail\_prog -t”);  
print MAIL "From: [george@medianomadz.com](mailto:george@medianomadz.com)  
";  
print MAIL "To: [george@medianomadz.com](mailto:george@medianomadz.com)  
";  
print MAIL "Subject: Estimate Request  
";  
print MAIL "

";

# 

#Body of the email

# 

print MAIL \<\<"(EOF)";

\*\*\* Estimate Inquiry \*\*\*

Confirmation # $abc  
Name: $name  
Company: $company  
Title: $title  
Address: $address  
$address2  
City/Town: $city  
Province: $province  
Country: $country  
Postal Code: $postal  
Phone: $phone  
Fax: $fax  
Email: $email  
Type in your inquiry below:  
$comment

(EOF)

close (MAIL);

#############################  
#Pointer to a Thank You page#  
#############################  
print "Location: [url=“[http://www.medianomadz.com/thankyou.htmnURI](http://www.medianomadz.com/thankyou.htmnURI)”][http://www.medianomadz.com/thankyou.htm](http://www.medianomadz.com/thankyou.htm)  
URI: [url=“[http://www.medianomadz.com/thankyou.htmnn](http://www.medianomadz.com/thankyou.htmnn)”][http://www.medianomadz.com/thankyou.htm](http://www.medianomadz.com/thankyou.htm)

" ;  
print \<\<"(END ERROR HTML)";  
Content-type: text/html  
\<html\>  
\<head\>  
\<title\>Thank You\</title\>  
\<!-- CSS --\>  
\<style type=“text/css”\>  
body  
{font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 11px; color: #ffffff}  
\</style\>  
\</head\>  
\<body bgcolor="#333333" alink="#660000" vlink="#666666" link="#660000"\>  
\<center\>  
\<b\>We are experiencing technical difficulties. Please visit the site again.\</b\>  
\<br\>  
\<b\>Thank you!\</b\>  
\</center\>  
\</body\>  
\</html\>  
(END ERROR HTML)  
}  
else  
{  
&error(‘request\_method’);  
}  
#end if request\_method  
}  
#end if check\_valid  
else  
{  
&error(‘bad\_referer’);  
}  
}  
#end if http\_referer  
else  
{  
&error(‘no\_referer’);  
}

[color=seagreen] **Here is my validate.js code:** [/color]

function checkWholeForm(theForm) {  
var why = “”;  
var flag = true  
why += checkName(theForm.name.value);  
why += checkCompany(theForm.company.value);  
why += checkCity(theForm.city.value);  
why += checkDropdownProv(theForm.province.selectedIndex);  
why += checkDropdownCountry(theForm.country.selectedIndex);  
why += checkPhone(theForm.phone.value);  
why += checkEmail(theForm.email.value);  
why += checkDropdownSelect(theForm.select.selectedIndex);  
if (why != “”) {  
alert(why);  
return false;  
}  
if (flag) {  
alert(“Form is valid! Submitting form…”)  
document.forms.theForm.submit()  
}  
return true;  
}

//—Name----|  
function checkName (strng) {  
var error = “”;  
if (strng == “”) {  
error = "You didn’t enter a Name.  
";  
}

var illegalChars = /\W/; // allow letters, numbers, and underscores  
if ((strng.length \< 2) || (strng.length \> 100)) {  
error = "You didn’t enter a Name.  
";  
}  
// else if (illegalChars.test(strng)) {  
// error = "The username contains illegal characters.  
";  
// }  
return error;  
}

//—Company----|  
function checkCompany (strng) {  
var error = “”;  
if (strng == “”) {  
error = "You didn’t enter a Company Name.  
";  
}  
return error;  
}

//—City----|  
function checkCity (strng) {  
var error = “”;  
if (strng == “”) {  
error = "You didn’t enter a City.  
";  
}  
return error;  
}

//—province----|  
function checkDropdownProv(choice) {  
var error = “”;  
if (choice == 0) {  
error = "Please choose a Provine/State from the list.  
";  
}  
return error;  
}

//—country----|  
function checkDropdownCountry(choice) {  
var error = “”;  
if (choice == 0) {  
error = "Please choose a Country from the list.  
";  
}  
return error;  
}

//—phone----|  
function checkPhone (strng) {  
var error = “”;  
if (strng == “”) {  
error = "You didn’t enter a Phone Number.  
";  
}  
var stripped = strng.replace(/[().-\]/g, ‘’); //strip out acceptable non-numeric characters  
if (isNaN(parseInt(stripped))) {  
error = “The phone number contains illegal characters.”;

}  
if (!(stripped.length == 10)) {  
error = "The phone number is the wrong length or contains invalid characters. Make sure you included an area code.  
";  
}  
return error;  
}

//—email----|

function checkEmail (strng) {  
var error="";  
if (strng == “”) {  
error = "You didn’t enter an valid E-mail address.  
";  
}  
var emailFilter=/^.+@.+…{2,3}$/;  
if (!(emailFilter.test(strng))) {  
error = "Please enter a valid email address.  
“;  
}  
else {  
//test email for illegal characters  
var illegalChars= /[()&lt;&gt;,;:\”[]]/  
if (strng.match(illegalChars)) {  
error = "Please enter a valid email address.  
";  
}  
}  
return error;  
}

//—select----|  
function checkDropdownSelect(choice) {  
var error = “”;  
if (choice == 0) {  
error = "How did you hear about Media Nomadz?  
";  
}  
return error;  
}

[color=seagreen]:rock: Thank you in advance.[/color]
