kaiman Posted November 8, 2009 Share Posted November 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180715-solved-form-field-validation-question/ Share on other sites More sharing options...
mrMarcus Posted November 8, 2009 Share Posted November 8, 2009 a value of 0 or "0" will return empty: empty() is this a static CAPTCHA system? if so, why not just make the question 1+1=x? Quote Link to comment https://forums.phpfreaks.com/topic/180715-solved-form-field-validation-question/#findComment-953430 Share on other sites More sharing options...
kaiman Posted November 8, 2009 Author Share Posted November 8, 2009 Yep this is a static system so I will change the question... Just out of curiosity, why does 0 return empty? Thanks, kaiman Quote Link to comment https://forums.phpfreaks.com/topic/180715-solved-form-field-validation-question/#findComment-953432 Share on other sites More sharing options...
kaiman Posted November 8, 2009 Author Share Posted November 8, 2009 * SOLVED * Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/180715-solved-form-field-validation-question/#findComment-953666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.