Force users to type a particular word in form

I have a basic php contact form with code along the lines of:

[php]

Name :

Telephone Number :

[/php]

and:

[php]if(isset($_POST[‘submit’])) {

$name = $_POST['name']; // required
$telephone_number = $_POST['telephonenumber']; // required
 
if($name=='' || 
$telephone_number=='' )

{		
die('You have not filled in all of the required fields - please hit your back button and try again!');    
}[/php]

etc etc…

I don’t need or want a captcha as such, but, as a midway point to avert some bots, am wondering if I can force users (using similar code as above) to type a simple given number - how would I adapt the code here to require a particular given number or word?

Honestly this isn’t a very good solution that you are trying to do but here is a sample of how.
[php]

Name :

Telephone Number :

Test (what is 4 + 16) :

[/php] [php] if(isset($_POST['submit'])) {

$name = $_POST[‘name’]; // required
$telephone_number = $_POST[‘telephonenumber’]; // required
$test = $_POST[‘test’];

  if($name=='' || 
  $telephone_number=='' || $test != 20 )
 
  {

die(‘You have not filled in all of the required fields - please hit your back button and try again!’);

}
[/php]

Thank you. I shall try this tomorrow morning. But I’m curious to know why you think this is a bad solution? From my point of view, captcha is known to put people off, yet not having one can result in annoying spam bot rubbish. This would provide a low level of protection & potentially be less annoying (or impossible to read) for users.

This works perfectly - thank you for this.

I’m still curious as to why it’s been suggested that this isn’t a good idea though. if the previous poster isn’t following this thread is there anyone else that has any thoughts?

Ok what I meant was that it’s not a “great” solution to the problem, but certainly a solution. It just really depends on how secure against bots you want it to be. It’s easy enough for a bot to scrape the html and with some predefined regex stuff they could probably determine what to do with the input field based on the text around it.

But as a normal failsafe it’s not horrible, google’s recaptcha is a much more secure way to do it.

OK thanks I see what you mean now. I don’t like captchas as a rule as it’s often 1 more excuse not to fill out a form, & google’s one is good, but ugly & is often near impossible to decipher. I don’t want potential clients discouraged.
I don’t have big problems but enough to want a low level barrier I can control fully myself.
To that end this is perfect.

Sponsor our Newsletter | Privacy Policy | Terms of Service