<?php
include('killercontact_files/functions.php');
if ($_POST['action'] == 'generate_form') {
if ($_POST['add_fullname'] == 1) {
if ($_POST['required_fullname'] == 1) {
$star = '<span class="required">*</span>';
$name = 'fullname';
$msg = 'Please enter your full name';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'fullname\']) < 1) {
$error_div .= getResultDiv(\'Please enter a value for your name\');
}';
} else {
$star = '';
}
$form .= '
<tr>
<td>' . $star . 'Full Name: </td>
<td><input type="text" name="fullname" value="<?php echo $form[\'fullname\']; ?>" size="40" /></td>
</tr>';
}
if ($_POST['add_first_last'] == 1) {
if ($_POST['required_first_last'] == 1) {
$star = '<span class="required">*</span>';
$name = 'first_last';
$msg = 'Please enter your full name';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'first_last\']) < 1) {
$error_div .= getResultDiv(\'Please enter a value for your name\');
}';
} else {
$star = '';
}
$form .= '
<tr>
<td>' . $star . 'Full Name: </td>
<td><input type="text" name="fullname" size="40" value="<?php echo $form[\'fullname\']; ?>" /></td>
</tr>';
}
if ($_POST['add_email'] == 1) {
if ($_POST['required_email'] == 1) {
$star = '<span class="required">*</span>';
$name = 'email';
$msg = 'Please enter your email';
$type = 'strlen_less';
$value = '5';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'email\']) < 1) {
$error_div .= getResultDiv(\'Please enter a value for your email address\');
}';
} else {
$star = '';
}
$form .= '
<tr>
<td>' . $star . 'E-mail: </td>
<td><input type="text" name="email" size="40" value="<?php echo $form[\'email\']; ?>" /></td>
</tr>';
}
if ($_POST['add_subjects'] == 1) {
if ($_POST['required_subjects'] == 1) {
$star = '<span class="required">*</span>';
$name = 'subject';
$msg = 'Please choose a subject';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'subject\']) < 1) {
$error_div .= getResultDiv(\'Please select a subject\');
}';
} else {
$star = '';
}
$form .= '
<tr>
<td>' . $star . 'Subject: </td>
<td>
<select name="subject" id="subject">
<option value="">Please choose a subject</option>
<option value="">----------------</option>
<?php echo $subject_options; ?>
</select></td>
</tr>';
}
if ($_POST['add_phone'] == 1) {
if ($_POST['required_phone'] == 1) {
$star = '<span class="required">*</span>';
$name = 'phone';
$msg = 'Please enter your phone number';
$type = 'phone';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'phone\']) < 6) {
$error_div .= getResultDiv(\'Please enter a valid phone number (too short) \');
}';
} else {
$star = '';
}
$php_validation .= '
$valid_chars = "0123456789-() ";
if (!checkValidChars($_POST[\'phone\'],$valid_chars)) {
$error_div .= getResultDiv(\'Please enter a valid (numbers, dashes and parenthesis) \');
}';
$form .= '
<tr>
<td>' . $star . 'Phone: </td>
<td><input type="text" name="phone" size="40" value="<?php echo $form[\'phone\']; ?>" /></td>
</tr>';
}
if ($_POST['add_company'] == 1) {
if ($_POST['required_company'] == 1) {
$star = '<span class="required">*</span>';
$name = 'company';
$msg = 'Please enter your company name';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'company\']) < 2) {
$error_div .= getResultDiv(\'Please enter your company name\');
}';
} else {
$star = '';
}
$form .= '
<tr>
<td>' . $star . 'Company: </td>
<td><input type="text" name="company" size="40" value="<?php echo $form[\'company\']; ?>" /></td>
</tr>';
}
if ($_POST['add_address'] == 1) {
if ($_POST['required_address'] == 1) {
$star = '<span class="required">*</span>';
$name = 'address';
$msg = 'Please enter your address';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$name = 'city';
$msg = 'Please enter your city';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$name = 'state';
$msg = 'Please enter your state';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$name = 'zip';
$msg = 'Please enter your zip code';
$type = 'novalue';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'address\']) < 1) {
$error_div .= getResultDiv(\'Please enter your address\');
}
if (strlen($_POST[\'city\']) < 1) {
$error_div .= getResultDiv(\'Please enter your city\');
}
if (strlen($_POST[\'state\']) < 1) {
$error_div .= getResultDiv(\'Please enter your state\');
}
if (strlen($_POST[\'zip\']) < 1) {
$error_div .= getResultDiv(\'Please enter your zip code\');
}
';
} else {
$star = '';
}
$form .= '
<tr>
<td>' . $star . 'Address: </td>
<td><input type="text" name="address" size="40" value="<?php echo $form[\'address\']; ?>" /></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="city" size="20" value="<?php echo $form[\'city\']; ?>" /> State:<input type="text" name="state" size="3" value="<?php echo $form[\'state\']; ?>" /> Zip: <input type="text" name="zip" size="10" value="<?php echo $form[\'zip\']; ?>" />
</td>
</tr>';
}
if ($_POST['add_address_2'] == 1) {
$star = '';
$form .= '
<tr>
<td>Address 2: </td>
<td><input type="text" name="address_2" size="40" value="<?php echo $form[\'address_2\']; ?>" /></td>
</tr>';
}
if ($_POST['add_comments'] == 1) {
if ($_POST['required_comments'] == 1) {
$star = '<span class="required">*</span>';
$name = 'comments';
$msg = 'Please enter 10 or more characters for the comments';
$type = 'strlen_less';
$value = '10';
$js_validation .= getValidation($add_edit,$name,$msg,$type,$value,'contact_validation');
$php_validation .= '
if (strlen($_POST[\'comments\']) < 10) {
$error_div .= getResultDiv(\'Please enter 10 or more characters for the comments\');
}';
} else {
$star = '';
}
$form .= '
<tr>
<td>' . $star . 'Comments: </td>
<td><?php echo $comments_textarea_1 . $comments_textarea_2; ?><?php echo $form[\'comments\']; ?><?php echo $end_textarea_1 . $end_textarea_2; ?></td>
</tr>';
}
$code = '
<?php
$comments_textarea_1 = "<text";
$comments_textarea_2 = \'area name="comments" cols="60" rows="6">\';
$end_textarea_1 = "</text";
$end_textarea_2 = "area>";
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 .= \'<option value="\' . $value_array[$i] . \'" \' . $selected . \'>\' . $value_array[$i] . \'</option>\';
$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 .= \'<li>\' . $value[$i] . \'</li>\';
}
if ($result_div != \'\') {
$result_div = \'<div class="\' . $class . \'"><ul>\' . $result_div . \'</ul></div>\';
}
} else {
if ($value != \'\') {
$result_div = \'<div class="\' . $class . \'">\' . $value . \'</div>\';
}
}
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("' . $_POST['subjects'] . '",$_POST[\'subject\']);
$email[\'to\'] = "' . $_POST['email_to'] . '";
$email[\'subject_prefix\'] = "' . $_POST['subject_prefix'] . '";
if ($_POST[\'action\'] == \'submit_form\') {
' . $php_validation . '
$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;
}
}
?>
<html>
<head>
<style>
.required {
font-weight:bold;
color:red;
}
.error-div {
border:1px solid #FF0000;
background-color:#FFDEDE;
padding:10px;
margin-bottom:5px;
color:#CC0000;
}
.success-div {
border:1px solid #09BD00;
background-color:#EEFFED;
padding:10px;
margin-bottom:5px;
color:#006600;
}
</style>
<script language="JavaScript" type="text/javascript">
var IE = (document.all) ? 1 : 0;
var DOM = 0;
if (parseInt(navigator.appVersion) >=5) {DOM=1};
function txtShow( cId, txt2show ) {
// Detect Browser
if (DOM) {
var viewer = document.getElementById(cId);
viewer.innerHTML=txt2show;
} else if(IE) {
document.all[cId].innerHTML=txt2show;
}
}//txtshow
function getTxt( cId ) {
var output = "";
// Detect Browser
if (DOM) {
var viewer = document.getElementById(cId);
output = viewer.value;
}
else if(IE) {
output = document.all[cId].value;
}
return output;
}//getTxt
function countChars(cBoxName, cTxtName, maxKeys) {
var str = new String(getTxt(cBoxName));
var len = str.length;
var showstr = \'<span class="alert-pos">\' + len + \' characters of \' + maxKeys + \' entered</span>\';
if (len > maxKeys) showstr = \'<span class="alert">\' + len + \' characters of \' + maxKeys + \' entered</span><br /><span class="alert">Too many characters, please edit content</span>\';
txtShow( cTxtName, showstr );
}
function ValidChars(sText,ValidChars) {
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++) {
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
}
}
return IsNumber;
}
function checkform (form) {
' . $js_validation . '
}
</script>
<title>' . $_POST['title'] . '</title>
</head>
<body>
<?php echo $result_div; ?>
<h1>' . $_POST['title'] . '</h1>
<form action="contact.php" onsubmit="return checkform(this);" method="post">
<input type="hidden" name="action" value="submit_form" />
<table>' . $form . '
</table>
<input type="submit" value="Submit Contact Form" />
</form>
<br /><br />' . getLink() . '
</body>
</html>
';
$copy_code = '<div class="code-div">Copy the code below by clicking on it and pressing CTL+C. Then paste it into a file called contact.php. Also make sure to <strong>create a page in the same directory called "results.php"</strong>. Visitors will be forwarded to this page when they are done filling out the form. Also note that there is a link at the bottom of each contact form with some surrounding text. This link and text <strong>cannot be removed</strong> from the form per a license agreement, however the link may be moved to a different part of the page.<br /><br /><form><textarea name="code" cols="40" onclick="this.form.code.select()" rows="4">' . $code . '</textarea></form></div>';
}
?>
<html>
<head>
<link href="killercontact_files/styles.css" rel="stylesheet" type="text/css"></link>
<style>
body {
font-family:Arial, Helvetica, sans-serif;
font-size:13px;
}
.code-div {
border:1px solid silver;
background-color:#FFFFFF;
padding:10px;
color:#006600;
}
.inputs-table {
font-size:11px;
border-collapse:collapse;
}
.inputs-table td {
border:1px solid silver;
background-color:#FFFFCC;
padding:2px;
}
.inputs-table th {
background-color:#FF6600;
color:#FFFFFF;
border:1px solid silver;
padding:2px;
}
</style>
</head>
<body>
<h1>Contact Form Killer v.1.4</h1>
<?php echo $result_div; ?>
<?php echo $copy_code; ?>
<p>To use Contact Form Killer, just enter in values for the top three inputes (E-mail, Subject Prefix and Title), and then check whatever boxes will be relivant. For instance, in a simple form with just e-mail and comments, click the "add" checkbox next to "E-mail" and "Comments". If you want these values to be required and validated with JavaScript and PHP, just check the box under "Required" next to the input. When you're done, click the "Generate Form Code" button.</p>
<form action="killercontact.php" method="post">
<input type="hidden" name="action" value="generate_form" />
<table class="inputs-table">
<tr>
<th>Variable</th>
<th>Value</th>
<tr>
<td>E-mail: </td>
<td><input type="text" name="email_to" size="40" value="<?php echo $_POST['email_to']; ?>"> (where the e-mail will be sent)</td>
</tr>
<tr>
<td>Subject Prefix: </td>
<td><input type="text" name="subject_prefix" size="40" value="<?php echo $_POST['subject_prefix']; ?>"></td>
</tr>
<tr>
<td>Title: </td>
<td><input type="text" name="title" size="40" value="<?php echo $_POST['title']; ?>"> (title of contact form, used in heading)</td>
</tr>
</table><br />
<table class="inputs-table">
<tr>
<th>Add</th>
<th>Required</th>
<th>Input</th>
</tr>
<tr>
<td><input type="checkbox" name="add_fullname" value="1" checked /></td>
<td><input type="checkbox" name="required_fullname" value="1" checked /></td>
<td>Full Name</td>
</tr>
<tr>
<td><input type="checkbox" name="add_email" value="1" checked /></td>
<td><input type="checkbox" name="required_email" value="1" checked /></td>
<td>E-mail</td>
</tr>
<tr>
<td><input type="checkbox" name="add_phone" value="1" /></td>
<td><input type="checkbox" name="required_phone" value="1" /></td>
<td>Phone</td>
</tr>
<tr>
<td><input type="checkbox" name="add_company" value="1" checked /></td>
<td><input type="checkbox" name="required_company" value="1" /></td>
<td>Company</td>
</tr>
<tr>
<td><input type="checkbox" name="add_address" value="1" /></td>
<td><input type="checkbox" name="required_address" value="1" /></td>
<td>Address</td>
</tr>
<tr>
<td><input type="checkbox" name="add_address_2" value="1" /></td>
<td></td>
<td>Address Line 2</td>
</tr>
<tr>
<td><input type="checkbox" name="add_comments" value="1" checked /></td>
<td><input type="checkbox" name="required_comments" value="1" checked /></td>
<td>Comments</td>
</tr>
<tr>
<td><input type="checkbox" name="add_subjects" value="1" /></td>
<td><input type="checkbox" name="required_subjects" value="1" /></td>
<td>Subject (separate possible subjects with commas)<br />
<textarea cols="40" rows="2" name="subjects"><?php echo $_POST['subjects']; ?></textarea>
</td>
</tr>
</table><br />
<input type="submit" value="Generate Form Code" />
</form>
<br />
<p><?php echo getLink(); ?></p>
</body>
</html>