I am trying to create a pseudo captcha to stop spambots spamming my contact form. I have php so that it doens't allow the user to send if the form isn't filled out and instead gives a message. I'm trying to make it so that it doesn't send if the "I am a robot" checkbox is checked as well. Since bots tend to check all checkboxes, I figured this may work. I am pretty new to PHP so go easy on me.
I tried using !empty($robots) which didn't work. I also tried !isset($robots) I messed with a second IF statement.
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$client_message = $_POST['client_message'];
$to = "rtisticpictures@gmail.com";
$subject = "Client Message";
$cmessage = $_POST['client_message'];
$message = $first_name . " " . $last_name . "\n\n Phone:" . $phone . "\n\n email:" . $email . "\n\n" . $cmessage;
if(empty($first_name) || empty($last_name) || empty($phone) || empty($cmessage) || empty($email))
{
echo "Your message can not be sent without all fields filled in, or you have checked that you are a robot. We do not allow bots to send email.";
; // Note this
}
else
{
mail ($to, $subject, $message, "From: " . $first_name . $last_name);
echo "Your message has been Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
HTML FORM
<form action="contact_form.php" method="post" name="contact_form">
<p>First Name: <input name="first_name" type="text" />
Last Name: <input name="last_name" type="text" />
Phone Number: <input name="phone" type="text" placeholder="(999)999-9999" />
E-mail:<input name="email" type="text" placeholder="your@email.com" />
</p>
<p>
<textarea name="client_message" cols="5" rows="3" placeholder="Write your message here."></textarea>
</p>
<div class="6u 12u(2)">
<input type="checkbox" id="human" name="human" unchecked="">
<label for="human">I am not a robot.</label></div>
<div class="6u 12u(2)">
<input type="checkbox" id="robots" name="robots" unchecked="">
<label for="robots">I am a robot.</label>
</div>
<p>
<input type="submit" name="submit" id="submit" value="Send"/>
<input type="reset" name="reset" id="reset" value="Clear"/>
</p>
</form>
I would like it to send only when the 'human' checkbox is selected and the 'robots' checkbox is not selected.
Aucun commentaire:
Enregistrer un commentaire