Hi, the problem i'm having is with the following code. When the user clicks the submit button with any errors it displays the section I've marked out. But it positions this at the very top of my form, pushing evverything down. Is there a way to get this error information into a different place? Maybe output it to a div or something?
Thanks for any help
The code:
<?php
//FIll out the settings below before using this script
$your_email = "mr.trilby@hotmail.co.uk";
$website = "Rizo Contact v1.9";
//BOTS TO BLOCK
$bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer|T8Abot|Syntryx|WinHttp|WebBandit|nicebot)/i";
//Check if known bot is visiting
if (preg_match($bots, $_SERVER["HTTP_USER_AGENT"])) {
exit ("Sorry bots are not allowed here!");
}
//Known Exploits
$exploits = "/(content-type|bcc:|cc:|from:|reply-to:|javascript|onclick|onload)/i";
//Spam words
$spam_words = "/(viagra|poker|blackjack|porn|sex)/i";
// BAD WORDS
$words = "/(
bitch|dick|pussy|pussies|ass|fuck|cum|cumshot|cum shot|
gangbang|gang bang|god dammit|goddammit|viagra|anus|analsex
)/i";
//BAD WORD/SPAM WORD/EXPLOIT BLOCKER
function wordBlock($word) {
//Make variables global
global $words;
global $spam_words;
if (preg_match($words, $word)) {
$word = preg_replace($words, "#####", $word);
}
if(preg_match($spam_words,$word)){
$word = preg_replace($spam_words,"$$$$",$word);
}
return $word;
}
function ex_clean($clean){
global $exploits;
if(preg_match($exploits,$clean)){
$clean = preg_replace($exploits,"",$clean);
}
return $clean;
}
//CLean data function
function dataClean($data) {
$data = addslashes(trim(rawurldecode(strip_tags($data))));
$data = filter_var ($data,FILTER_SANITIZE_SPECIAL_CHARS);
return $data;
}
//CREATE MAIN VARIABLES
$name = (isset ($_POST['name'])) ? dataClean(ex_clean($_POST['name'])) : FALSE;
$email = (isset ($_POST['email'])) ? dataClean(ex_clean(filter_var($_POST['email'],FILTER_SANITIZE_EMAIL))) : FALSE;
$subject = (isset ($_POST['subject'])) ? dataClean(ex_clean($_POST['subject'])) : FALSE;
$comment = (isset ($_POST['message'])) ? wordBlock(dataClean($_POST['message'])) : FALSE;
$submit = (isset ($_POST['send'])) ? TRUE : FALSE;
$email_check = "/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i";
$spam = (isset($_POST['spam'])) ? dataClean($_POST['spam']) : FALSE;
$ip = $_SERVER["REMOTE_ADDR"];
$errors = array();
///////////////////////////////////THIS PART/////////////////////////////////
//Check if send button was clicked
if ($submit) {
if(!$spam)
{
$errors[] = "Please enter the code seen inside the image this is to prevent automated submissions!!!";
}
if($spam)
{
if($spam !== $_SESSION['captcha'])
{
$errors[] = "The spam code you entered is incorrect!!!";
}
}
if (!$name) {
$errors[] = "Please enter a name!!!";
}
if ($name) {
if(!ctype_alpha($name)){
$errors[] = "Name must contain only letters A-Z!!!";
}
}
if (!$email) {
$errors[] = "Please enter an email address!";
}
if ($email) {
if (!preg_match($email_check, $email)) {
$errors[] = "The E-mail you entered is invalid!";
}
}
if (!$subject) {
$errors[] = "Please enter a subject!";
}
if (!$comment) {
$errors[] = "Please don't leave the message field blank!";
}
//If bot trap is tripped exit the script
if(isset($_POST['Email_address']) ? $_POST['Email_address'] : FALSE ){
exit();
}
//Check if any errors are present
if (count($errors) > 0) {
foreach ($errors AS $error) {
print "• $error <br />";
}
}
else {
//////////////////////////////////////////////////////////////////////////////
//MESSAGE TO SEND TO ADMIN
//Create main headers
$headers = "From: " . $website . " <$your_email> \n";
$headers .= "Reply-to:" . $email . " \n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-Type: text/html; charset=UTF-8\n";
$message = "";
$message .= "<h1>New E-Mail From " . $website . "</h1><br /><br />";
$message .= "<b>Senders IP:</b>" . $ip . "<br />";
$message .= "<b>Senders Name:</b>" . $name . "<br />";
$message .= "<b>Senders E-mail:</b>" . $email . "<br />";
$message .= "<b>Senders Subject:</b>" . $subject . "<br />";
$message .= "<b>Senders Message:</b>" . $comment . "<br />";
//E-mails subject
$mail_subject = "New E-mail From " . $website . "";
/*
CHECK TO BE SURE FIRST E-MAIL TO ADMIN IS A SUCCESS AND SEND EMAIL TO ADMIN
OTHERWISE DON'T SEND AUTO RESPONCE
*/
if (mail($your_email, $mail_subject, $message, $headers)) {
//UNSET ALL VARIABLES
unset ($name, $email, $subject, $reason, $comment, $_REQUEST);
//JAVASCRIPT SUCCESS MESSAGE
echo "
<script type='text/javascript' language='JavaScript'>
alert('Your message has been sent');
</script>
";
//SUCCESS MESSAGE TO SHOW IF JAVASCRIPT IS DISABLED
echo "<noscript><p>THANK YOU YOUR MESSAGE HAS BEEN SENT</p></noscript>";
/*
-----------------END MAIL BLOCK FOR SENDING TO ADMIN AND START AUTO RESPONCE SEND-----------------
*/
//AUTO RESPONCE MESSAGE
//Create main headers
$headers = "From: " . $website . " <$your_email> \n";
$headers .= "Reply-to:" . $your_email . " \n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "Content-Type: text/html; charset=UTF-8\n";
$message = "";
$message .= "<h1>Thank You For Contacting Us </h1><br /><br />";
$message .= "On behalf of <b>" . $website . "</b> we wanna thank you for contacting us and to let you know we will respond to your message as soon as possible thank you again.";
//E-mails subject
$mail_subject = "Thank you for contacting " . $website . "";
//Send the email
mail($email, $mail_subject, $message, $headers);
/*
-----------------END MAIL BLOCK FOR SENDING AUTO RESPONCE -----------------
*/
}
else {
echo "
<script type='text/javascript' language='JavaScript'>
alert('Sorry could not send your message');
</script>
";
echo "<noscript><p style='color:red;'>SORRY COULD NOT SEND YOUR MESSAGE</p></noscript>";
}
UNSET($_SESSION['captcha']);
}
}
?>
I want the error information to be shown in a div, is this possible?