Adding Challenge Questions
I am trying to figure out how to add 2 challenge questions to my single.php file. I want to replace the
"add the numbers" with the two challenge question because I have too many spam-bots getting through to people who have posted ads.
I figured out how to get one question going, but I can NOT figure out how to add a second question. Whatever I name the second question it will NOT validate it properly. For some reason the only name that works is the
name="term"; which I used for the first challenge question. I tried to add a second question and name it
name="term2" for example, but it does NOT validate even after I add it to the
$email_err . section of the code below.
My hope is that having two simple challenge questions, each with 8 possible answers in a dropdown box, that spam-bots will not be able to guess the 2 correct answers at the same time; therefore spam-bot emails will NOT get sent to ad posters.
Here is how I have the
Contact Ad Owner set up now if you need to see what I am trying to do:
http://chiobo.com/free-investing-guide/960
As you can see right now for emails to be sent they have to answer the question
What color is the sky? and enter the
add the numbers. So I would like to remove the add the numbers and replace it with a second simple challenge question.
================================================== =========
Below highlighted in red is the code I am currently using for the first challenge question:
================================================== =========
<?php if (get_option('email_form') == "yes" || get_option('email_form') == "") { ?>
<div class="email_form">
<h3>
<?php _e('Contact Ad Owner','cp'); ?></h3>
<?php
$email_err = "";
$email_ok = "";
if (isset($_POST['action']) && $_POST['action'] == 'email') {
$subject2 = "Re: ".get_the_title();
$name2 = strip_tags($_POST['name2']);
$email2 = strip_tags($_POST['email2']);
// $receiver_email = strip_tags($_POST['receiver_email']);
// $receiver_email = str_replace("gd6j83ksl", "@", $receiver_email);
// $receiver_email = str_replace("m3gd0374h", ".", $receiver_email);
$receiver_email = trim(get_post_meta($post->ID, "email", true));
$message2 = strip_tags($_POST['message2']);
if ( $term == "Black") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $term == "Pink") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $term == "Red") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $term == "Yellow") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $term == "Purple") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $term == "Green") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $term == "Orange") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $term == "") {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $name2 == "") {
$email_err .= __('Enter your name!','cp') . "
";
}
if ( $email2 == "") {
$email_err .= __('Enter your email address!','cp') . "
";
} else {
if ( !cp_check_email($email2) ) {
$email_err .= __('Email format is incorrect!','cp') . "
";
}
}
if ( $message2 == "") {
$email_err .= __('Enter a message!','cp') . "
";
}
$email_total = (int)$_POST['email_total'];
$email_nr1 = (int)$_POST['email_nr1']; $email_nr1 = str_replace("60293", "", $email_nr1);
$email_nr2 = (int)$_POST['email_nr2']; $email_nr2 = str_replace("36202", "", $email_nr2);
$email_nr1nr2 = $email_nr1 + $email_nr2;
if ( $email_total != $email_nr1nr2 ) {
$email_err .= __('The spam field is incorrect!','cp') . "
";
}
if ( $email_err == "" ) {
$body = __('Someone is interested in your classified ad! They sent you a message from the following page:','cp') . "\n\n" . selfURL()."
\n
Name: $name2
Email: $email2
Message: $message2
";
// $receiver_email = "tester@localhost"; //uncomment this line to test locally
// ini_set('sendmail_from', 'me@domain.com'); //this line might need to be enabled for some people using Windows hosted sites
mail($receiver_email,$subject2,$body,"From: $email2");
$email_ok = "ok";
unset($receiver_email, $name2, $email2, $message2, $subject2);
}
}
?>
<a name="email-form"></a>
<center><?php
if ( $email_err != "" ) {
echo "<div class=\"email_err\">$email_err</div>";
}
?></center>
<center><?php
if ( $email_ok == "ok" ) {
echo "<div class=\"email_ok\">" . __('Your email has been sent.','cp') . "</div>";
}
?></center>
<?php if (get_option('expand_email_form') == "yes" ) { ?>
<div id="email_form_data">
<?php } else { ?>
<div id="email_form_data" <?php if ($email_err == "") { echo "style=\"display: none;\""; } ?>>
<?php } ?>
<form action="<?php the_permalink(); ?>#email-form" method="post">
<?php _e('Name','cp'); ?>:
<input type="text" name="name2" value="<?php echo $name2;?>" />
<?php _e('Email','cp'); ?>:
<input type="text" name="email2" value="<?php echo $email2;?>" />
<?php _e('Subject','cp'); ?>:
<div class="like_input"><?php _e('Re:','cp'); ?> <?php the_title(); ?></div>
<?php _e('Message','cp'); ?>:
<textarea name="message2" rows="1" cols="2"><?php echo $message2;?></textarea>
<center><u>Spam-Bot Challenge Questions</u>:</center>
<center><label for="challenge1">What color is the sky?</label>
<select name="term" "value="<?php echo term;?>" />
<option value=''>Select One</option>
<option>Purple</option>
<option>Green</option>
<option>Blue</option>
<option>Orange</option>
<option>Black</option>
<option>Pink</option>
<option>Red</option>
<option>Yellow</option>
</select></center>
<input type="hidden" name="action" value="email" />
<div class="capcha" style="text-align: center;">
<?php
$email_nr1 = rand("0", "9");
$email_nr2 = rand("0", "9");
?>
<?php echo $email_nr1; ?> + <?php echo $email_nr2; ?> = <input type="text" name="email_total" class="email_captcha" maxlength="2" value="" />
<input type="hidden" name="email_nr1" value="60293<?php echo $email_nr1; ?>" />
<input type="hidden" name="email_nr2" value="36202<?php echo $email_nr2; ?>" />
</div>
<input type="submit" style="width:240px;" name="send" value="<?php _e('Send Email','cp'); ?>" />
</form>
</div>
</div>
================================================== ====================================
Any ideas would be appreciated.
Thanks,
Chad