Contact
//This “clean” function is for the forms, protects against email header injection.
function clean($input) {
$bad_chars = array(”%0A”, “%0D”, “%0a”, “%0d”, “\n”, “\n”, “\r”, “\r”);
$cleaninput = str_replace($bad_chars, “”, $input);
$cleaninput = stripslashes($cleaninput);
return $cleaninput;
}
if (!$_POST[’form_submitted’]) {
echo ”
“;
} else {
$form_name = clean($_POST[’form_name’]);
$form_email = clean($_POST[’form_email’]);
$form_phone = clean($_POST[’form_phone’]);
$form_hear = $_POST[’form_hear’];
if ($form_hear==”other”) {$form_hear = clean($_POST[’form_hearother’]); }
if ($_POST[’isbook’]) {
$form_isbn = clean($_POST[’form_isbn’]);
$form_author = clean($_POST[’form_author’]);
$form_title = clean($_POST[’form_title’]);
$form_bookinfo = clean($_POST[’form_bookinfo’]);
}
$form_inquiry = clean($_POST[’form_inquiry’]);
if (!$_POST[’isbook’]) {
if (!$form_name && !$form_inquiry) {
echo ”
Error submitting form
“;
echo ”
Please use your browser’s \”back\” button and ensure that you’ve filled out all requested information on the form, then try submitting again. You must provide at least your name and a comment.
“;
$valid = “no”;
}
} elseif ($_POST[’isbook’]) {
if (!$form_name || !($form_phone || $form_email) || !($form_isbn || $form_author || $form_title || $form_bookinfo)) {
echo ”
Error submitting form
“;
echo ”
Please use your browser’s \”back\” button and ensure that you’ve filled out all requested information on the form, then try submitting again. You must provide at least your name, one piece of contact information, and one piece of information about the book you are interested in ordering.
“;
$valid = “no”;
}
}
if ($valid==”no”) {
} else {
$form_message = “You have been contacted by “.$form_name;
if ($form_email || $form_phone) {
$form_message .= ” who can be contacted at “;
if ($form_email) {$form_message.=$form_email; }
if ($form_phone) {$form_message.=” or “.$form_phone; }
}
$form_message .= “.\n”;
if ($form_hear || $form_hearother) {$form_message .= “. He/she heard about The Book Cellar/Bartelby’s through “;
if ($form_hear) {$form_message .= $form_hear;} else {$form_message .= $form_hearother;}
$form_message .= “.\n”;
}
if ($_POST[’isbook’]) {
$form_message .= “He/she is interested in ordering the following book: \n”;
if ($form_isbn) {$form_message .= “ISBN: “.$form_isbn;}
if ($form_author) {$form_message .= ” Author: “.$form_author;}
if ($form_title) {$form_message .= ” Title: “.$form_title;}
if ($form_bookinfo) {$form_message .= “\nOther info: “.$form_bookinfo;}
$form_message .= “\n”;
}
if ($form_inquiry) {$form_message .= “Questions or comments: \n”.$form_inquiry; }
$form_to = “info@bookcellarvt.com”;
$form_subject = “Form submission from “.$form_name;
$form_from = “From: “.$form_email;
mail($form_to, $form_subject, $form_message, $form_from);
echo ”
Form has been submitted successfully, thank you!
“;
if ($_POST[’isbook’]) {
echo ”
We will be in touch with you shortly regarding the book you have requested.
“;
} elseif ($form_email || $form_phone) {
echo ”
We will be in touch with you shortly.
“;
}
}
}
?>
