View Full Version : Php form a field will only submit when a certain number is entered
Hello.
I am wanting to spam proof my form simply by adding a field where a certain value like '11' is entered for it to submit. The text would be 'seven + four =' and the value must be 11 or the form will not submit.
How do I do this easily?
Thanks
fastsol1
10-03-2010, 02:47 PM
Use a if() to check if the field is equal to 11. You will need to obviously add the field in your form named check_number in order for this to work.
if (isset($_POST['submit']))
{
$check = $_POST['check_number'];
if ($check=="11")
{
/* Subject and Email Variables */
$emailSubject = 'Basement Studio Web Enquiry';
$webMaster = 'info@basement-studios.co.uk';
/* Gathering Data Variables */
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$artistField = $_POST['artist'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$body ="
<br><hr><br>
Name: $name<br>
Email: $email<br>
Artist: $artist<br>
Subject: $subject<br>
Message: $message<br>
";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$seccess = mail($webMaster, $emailSubject, $body, $headers);
/* Results as HTML */
$theResults ="<html><body>Congrats!!</body></html>";
echo "$theResults";
}
else
{
echo "You did not enter the correct number";
}
}
Honestly I have no idea what your piece of code - <<EOD means, but it was causing the code not to read right for what I told you to do so I removed that and you can put it back in if you need it but I have never seen that before.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.