I'm testing a very simple captcha on my website's contact form, because the form is being abused by spambots. I'm at the beginning of the learning curve with php, and plan to refine this captcha in the future. Meanwhile, there is a specific issue I'd like to resolve... The php code generates messages which prompt the visitor to complete required form fields, and all but one of these messages appear as popups, without opening a new browser window. However, a message informing the visitor of a captcha error opens a new browser window. When that happens, the visitor needs to use the back button, and repopulate the contact form. Some browsers preserve the form field data, but not Internet Explorer. I don't know why that particular message behaves this way, but I'd prefer the message appear as a popup, like the other messages. For example, if the Email field doesn't contain a valid Email address, there is a message prompting the visitor to correct it. Please advise how to adjust my code so that a captcha error can be corrected without leaving the contact form page. The contact page is at www.mauitradewinds.com/contact.htm
and the php code snippet is attached.
$errors = '';
$myemail = 'firstname.lastname@example.org';//<-----Put Your email address here.
$errors .= "\n Error: At a minimum, we need your name, Email address and message in order to transmit your form.";
$firstname = array_key_exists('firstname',$_POST) ? $_POST['firstname']:'';
$lastname = array_key_exists('lastname',$_POST) ? $_POST['lastname']:'';
$email_address = array_key_exists('email',$_POST) ? $_POST['email']:'';
$message = array_key_exists('message',$_POST) ? $_POST['message']:'';
$captcha = array_key_exists('captcha',$_POST) ? $_POST['captcha'] : FALSE;
$errors .= "\n Error: Invalid email address";
$errors .= "\n Error: Please check your spelling and try again";
$to = $myemail;
$email_subject = "Contact form";
$email_body = "You have received a contact form from Site-1. ".
" Here are the details:\n First Name: $firstname \n Last Name: $lastname \n Email: $email_address \n Message: \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
//redirect to the 'thank you' page
exit;//You should always "exit" immediately after a redirection request
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>Contact form handler</title>
<!-- This page is displayed only if there is some error -->