Jump to content

[SOLVED] form field validation question


kaiman

Recommended Posts

I am currently working on an account signup script and have a form field called "math" that works as a simple Captcha and asks the following question:

 

Anti-Spam Question: 1 - 1 = ?

 

Of course as we know the answer is zero/0

 

However, in my php script when I run this code it will return as empty when someone enters the number "0" rather then typing "zero", or "Zero", or "ZERO", but returns true if they enter any of the last three options.

 

<?php
// validate math function and check for empty fields
if ($math != "0" && $math != "zero" && $math != "Zero" && $math != "ZERO") {
   echo "You Did Not Answer the Math Problem Correctly";
  exit ;
}
if (empty($math)) {
   echo "Please Complete All Form Fields";
  exit ;
}
?>

 

My question is how come it won't recognize the number 0 and is there a way to prevent this from happening?

 

Any help would be appreciated.

 

Thanks,

 

kaiman

Link to comment
https://forums.phpfreaks.com/topic/180715-solved-form-field-validation-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.