<?php
$formvars = array(
array ("name", "text", "empty", "name"),
array ("email","text", "empty", "email"),
array ("address", "text", "empty", "address"),
array ("herd", "text", "empty", "herd size"),
array ("current", "text", "empty", "current parlor", "Current Parlor"),
array ("dealer", "text", "empty", "preferred local dealer", "Preferred Local Dealer"),
array ("monza", "checkbox"),
array ("daytona", "checkbox"),
array ("rapid", "checkbox"),
array ("swing", "checkbox"),
array ("step", "checkbox"),
array ("flow", "checkbox"),
array ("magnum", "checkbox"),
array ("telephone", "text", null, null, "phone"),
array ("fax", "text"),
array ("mobile", "text"),
array ("new", "text", null,null,"newparlor"),
array ("select", "text", null, null, "Currently Using BGM Products"));
$errormessage = "";
if (!validate("POST")):
die ($errormessage);
else:
$cleansed = cleansedata("POST");
$formcontent = buildFormContent();
$recipient = "me@here.com";
$subject = "Email Form\r\n";
$mailheader = "From: $email\r\n";
$mailheader .= "Cc: $email\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
$result = mail($recipient, $subject, $formcontent, $mailheader);
if ($result):
echo '<p><b>Form submitted successfully</b></p>';
else:
echo "problem sending mail";
endif;
endif;
function validate($type="POST") {
global $formvars, $errormessage;
$validate = true;
foreach ($formvars as $formvar):
if (isset($formvar[2])):
switch ($formvar[2]):
case "empty":
if (empty($_{$type}[$formvar[0]])):
$errormessage .= "<span style=\"color:red;\">You did not provide your ". $formvar[3] . "!</span><br/>";
$validate=false;
endif;
break;
endswitch;
endif;
endforeach;
return $validate;
}
function cleansedata($type="POST"){
global $formvars;
foreach ($formvars as $formvar):
if (magic_quotes_gpc()):
if(isset($_{$type}[$formvar[0]])):
$cleansed[$formvar[0]] = stripslashes($_{$type}[$formvar[0]]);
else:
$cleansed[$formvar[0]] = "No Data Provided";
endif;
endif;
endforeach;
return $cleansed;
}
function doCheckBoxes() {
global $formvars, $cleansed;
foreach ($formvars as $formvar):
if ($formvar[1] === "checkbox"):
if ($cleansed[$formvar[0]] === "No Data Provided"):
$cleansed[$formvar[0]] = "User has not selected " .$formvar[0];
else:
$cleansed[$formvar[0]] = "User has selected " .$formvar[0];
endif;
endif;
endforeach;
}
function buildFormContent() {
global $formvars, $cleansed;
$date = date("l, F j, Y");
$content = $date ."\r\n";
foreach ($formvars as $formvar):
$label = isset($formvar[4]) ? $formvar[4] : $formvar[0];
$content .= <<<EOL
$label: {$cleansed[$formvar[0]]}
EOL;
endforeach;
}
?>