';
$end_textarea_1 = "";
if (!function_exists('str_split')) {
function str_split($string, $split_length = 1) {
return explode("\r\n", chunk_split($string, $split_length));
}
}
function generateDropDown($values,$value_selected) {
$value_array = explode(',',$values);
$i = 0;
while ($value_array[$i] != '') {
if ($value_array[$i] == $value_selected) {
$selected = ' selected ';
} else {
$selected = '';
}
$options .= '';
$i++;
}
return $options;
}
function checkValidChars($string,$valid_chars) {
$string_array = str_split($string);
$valid_chars_array = str_split($valid_chars);
$i = 0;
while ($string_array[$i] != '') {
if (!in_array($string_array[$i],$valid_chars_array)) {
return false;
}
$i++;
}
return true;
}
function getResultDiv($value,$type='error') {
// Formats successful or error results whether they are in an array or a snippet.
if ($type == 'success') {
$class = 'success-div';
} elseif ($type == 'test') {
$class = 'test-div';
} else {
$class = 'error-div';
}
if (is_array($value)) {
for ($i = 0; $value[$i] != ''; $i++) {
$result_div .= '
' . $value[$i] . '';
}
if ($result_div != '') {
$result_div = '';
}
} else {
if ($value != '') {
$result_div = '' . $value . '
';
}
}
return $result_div;
}
function getValidation($add_edit,$name,$msg,$type,$value='') {
global $edit_action;
global $add_action;
global $error_div;
global $_POST;
global $_GET;
if ($_POST['action'] == "submit_form") {
$do = 1;
}
// No value
if ($type == 'novalue') {
if ($do == 1) {
if (strlen($_POST[$name]) < '1') {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value == ""';
return jsCheck($js_clause,$msg,$name);
}
// Number is less than
if ($type == 'less_than') {
if ($do == 1) {
if ($_POST[$name] < $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value < ' . $value;
return jsCheck($js_clause,$msg,$name);
}
// Number is greater than
if ($type == 'greater_than') {
if ($do == 1) {
if ($_POST[$name] > $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value > ' . $value;
return jsCheck($js_clause,$msg,$name);
}
// Value equals
if ($type == 'equals') {
if ($do == 1) {
if ($_POST[$name] == $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value == ' . $value;
return jsCheck($js_clause,$msg,$name);
}
// Less Than String Length
if ($type == 'strlen_less') {
if ($do == 1) {
if (strlen($_POST[$name]) < $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value.length < ' . $value;
return jsCheck($js_clause,$msg,$name);
}
// String Length
if ($type == 'strlen') {
if ($do == 1) {
if (strlen($_POST[$name]) != $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value.length != ' . $value;
return jsCheck($js_clause,$msg,$name);
}
// Zip Code
if ($type == 'zip') {
$valid_chars = "0123456789";
if ($do == 1) {
if (strlen($_POST[$name]) != 5) {
$error_div .= getResultDiv('Please enter 5 digits for the zip code');
} elseif (!checkValidChars($_POST[$name],$valid_chars)) {
$error_div .= getResultDiv('Please enter only digits for the zip code');
}
}
$js_clause_1 = 'form.' . $name . '.value.length != 5';
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';
return
jsCheck($js_clause_1,'Please enter 5 numbers for the zip code',$name) .
jsCheck($js_clause_2,'Please enter only numbers in the zip code',$name);
}
// Price
if ($type == 'price') {
$valid_chars = "0123456789.,";
if ($do == 1) {
$post_value = str_replace(',','',$_POST[$name]);
if (!checkValidChars($post_value,$valid_chars)) {
$error_div .= getResultDiv('Please enter only a number for ' . $msg);
} elseif (strlen($post_value) > $value) {
$error_div .= getResultDiv('Please enter a smaller value for ' . $msg);
}
}
$js_clause_1 = 'form.' . $name . '.value.length > ' . $value;
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';
return
jsCheck($js_clause_1,'Please enter no more than ' . $value . ' characters for ' . $msg,$name) .
jsCheck($js_clause_2,'Please enter only numbers for ' . $msg,$name);
}
// Number
if ($type == 'number') {
$valid_chars = "0123456789";
if ($do == 1) {
$post_value = str_replace(',','',$_POST[$name]);
if (!checkValidChars($post_value,$valid_chars)) {
$error_div .= getResultDiv('Please enter only a number for ' . $msg);
} elseif (strlen($post_value) > $value) {
$error_div .= getResultDiv('Please enter a smaller value for ' . $msg);
}
}
$js_clause_1 = 'form.' . $name . '.value.length > ' . $value;
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';
return
jsCheck($js_clause_1,'Please enter no more than ' . $value . ' numbers for ' . $msg,$name) .
jsCheck($js_clause_2,'Please enter only numbers for ' . $msg,$name);
}
// Phone Number
if ($type == 'phone') {
$valid_chars = "0123456789-() ";
$value = 7;
if ($do == 1) {
if (!checkValidChars($_POST[$name],$valid_chars)) {
$error_div .= getResultDiv('Please enter only a phone number for ' . $msg);
} elseif (strlen($post_value) > $value) {
$error_div .= getResultDiv('Please enter a smaller value for ' . $msg);
}
}
$js_clause_1 = 'form.' . $name . '.value.length < ' . $value;
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';
return
jsCheck($js_clause_1,'Please enter no more than ' . $value . ' numbers for the phone number',$name) .
jsCheck($js_clause_2,'Please enter a valid phone number',$name);
}
// Password
if ($type == 'password') {
$valid_chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ($do == 1) {
if (!checkValidChars($_POST[$name],$valid_chars)) {
$error_div .= getResultDiv('Please enter only alpha-numeric values for ' . $msg);
} elseif (strlen($_POST[$name]) < $value || $_POST[$name] == '') {
$error_div .= getResultDiv($msg . ' must be at least 6 characters long');
}
}
$js_clause_1 = 'form.' . $name . '.value.length < ' . $value . ' && ' . ' form.' . $name . '.value.length > 0';
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';
return
jsCheck($js_clause_1,$msg . ' must be at least 6 characters long',$name) .
jsCheck($js_clause_2,'Please enter only alpha-numeric values for ' . $msg,$name);
}
// Duplicate
if ($type == 'duplicate') {
if ($do == 1) {
$value_array = explode(':',$value);
$table = $value_array[0];
$column = $value_array[1];
$content = $_POST[$name];
}
}
}
function jsCheck($clause,$msg,$name) {
return '
if (' . $clause . ') {
alert( "' . $msg . '" );
form.' . $name . '.focus();
return false;
}
';
}
$subject_options = generateDropDown("Provide Names,Provide Information,Ask Question",$_POST['subject']);
$email['to'] = "information@anthonycavanagh.co.uk";
$email['subject_prefix'] = "Information";
if ($_POST['action'] == 'submit_form') {
if (strlen($_POST['fullname']) < 1) {
$error_div .= getResultDiv('Please enter a value for your name');
}
if (strlen($_POST['email']) < 1) {
$error_div .= getResultDiv('Please enter a value for your email address');
}
if (strlen($_POST['subject']) < 1) {
$error_div .= getResultDiv('Please select a subject');
}
if (strlen($_POST['comments']) < 10) {
$error_div .= getResultDiv('Please enter 10 or more characters for the comments');
}
$result_div .= $error_div;
if ($error_div == '') {
if (strlen($_POST["subject"] ) > 1) {
$message .= "SUBJECT: " . $_POST["subject"] . "\n";
}
if (strlen($_POST["fullname"]) > 1) {
$message .= "FROM: " . $_POST["fullname"] . "\n";
}
if (strlen($_POST["email"]) > 1) {
$message .= "EMAIL: " . $_POST["email"] . "\n";
}
if (strlen($_POST["phone"] ) > 1) {
$message .= "PHONE: " . $_POST["phone"] . "\n";
}
if (strlen($_POST["company"] ) > 1) {
$message .= "COMPANY: " . $_POST["company"] . "\n";
}
if (strlen($_POST["address"] ) > 1) {
$message .= "Address: " . $_POST["address"] . " " . $_POST["address_2"] . " " . $_POST["city"] . ", " . $_POST["state"] . " " . $_POST["zip"] . "\n";
}
if (strlen($_POST["comments"] ) > 1) {
$message .= "COMMENTS:\n" . $_POST["comments"] . "\n\n";
}
$message = "Below is the information submitted to your online Contact form on " . date('F j, Y') . " at " . date('j:i a') . ":\n\n" . $message;
if (mail($email['to'],$email['subject_prefix'] . $_POST['subject'], $message, "From: " . $_POST['email'])) {
header("Location: results.php");
}
} else {
$form = $_POST;
}
}
?>
Provide Information
Provide Information