The contact form on my website has been abused by spam bots. I'd like to try a captcha method, referred to as "honeypot", which presents an invisible text field that "tempts" a spam bot to populate it. If the text field is filled in, the form will not be submitted, but a phoney acknowledgment page will appear. If the text field is left blank, the form will be submitted, and an authentic acknowledgment page will appear. The contact form has a section, styled "display:none" which asks the visitor to solve a simple arithmetic problem, and type the answer into a text field. That field is named "captcha".
Below is php code for the contact form handler. I'd appreciate help with adding code to detect whether the "captcha" field has been populated. If it has been populated, the form should not really be submitted, but the visitor's browser should load a page which looks like an acknowledgment. If the captcha field has been left blank, the form should be submitted, and the "thanyou.htm" page should load.
$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']:'';
$Address = array_key_exists('Address',$_POST) ? $_POST['Address']:'';
$City = array_key_exists('City',$_POST) ? $_POST['City']:'';
$State = array_key_exists('State',$_POST) ? $_POST['State']:'';
$Zip = array_key_exists('Zip',$_POST) ? $_POST['Zip']:'';
$Country = array_key_exists('Country',$_POST) ? $_POST['Country']:'';
$Phone = array_key_exists('Phone',$_POST) ? $_POST['Phone']:'';
$email_address = array_key_exists('email',$_POST) ? $_POST['email']:'';
$message = array_key_exists('message',$_POST) ? $_POST['message']:'';
$errors .= "\n Error: Invalid email address";
$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 Address: $Address \n City: $City \n State: $State \n Zip: $Zip \n Country: $Country \n Phone: $Phone \n Email: $email_address \n Message: $message \n captcha: $captcha";
$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 -->