jay4708 Posted October 23, 2009 Share Posted October 23, 2009 Hi I hope somebody can help me with what will probably be really simple, I'm pulling my hair trying to get my head round it. I've got a contact form and I would like to add to it a couple of simple human check questions like "what is 1 + 1?". I've got it to work with the answer being '2' but what i would like to do is have it also validate if the visitor enters 'two'. This is how I did it for just the number '2' if (Trim($Human_check_1)!="2") $validationOK=false; Could somebody please tell me how I can code it so "if Human_check_1 is equal to '2' or it is equal to 'two' the validation is true" Thanks Jay Link to comment https://forums.phpfreaks.com/topic/178768-help-please-how-to-validate-from-2-possible-answers/ Share on other sites More sharing options...
salathe Posted October 23, 2009 Share Posted October 23, 2009 $validationOK = FALSE; if (trim($Human_check_1) == "2" OR strtolower(trim($Human_check_1)) == "two") { $validationOK = TRUE; } Reading: 1. Logical operators (the OR) 2. strtolower function Link to comment https://forums.phpfreaks.com/topic/178768-help-please-how-to-validate-from-2-possible-answers/#findComment-943012 Share on other sites More sharing options...
jay4708 Posted October 23, 2009 Author Share Posted October 23, 2009 Thank you very much, its so easy when you know how All working fine now. Jay Link to comment https://forums.phpfreaks.com/topic/178768-help-please-how-to-validate-from-2-possible-answers/#findComment-943034 Share on other sites More sharing options...
jay4708 Posted October 25, 2009 Author Share Posted October 25, 2009 Back again. I've been trying to add another Human check to my form so there are two on there but every time I do it the other human check stops working, what am I doing wrong? Here is the code that I've just tried and this time the Human Check 1 (answer '7 or seven') is not working, but it does in the format that it is if I move it below the human check 1 Ignore my notes in the code, I'm learning, they help me remember. // validation, check for required fields $validationOK=true; if (Trim($Name)=="") $validationOK=false; // If Name field is left blank validation fails if (Trim($Tel)=="") $validationOK=false; if (!is_numeric($Tel)) $validationOK=false; // If Telephone field has non-numeric characters included validation fails if (Trim($Email)=="") $validationOK=false; if (Trim($Message)=="") $validationOK=false; $validationOK=false; if (trim($Human_check_1) == "7" OR strtolower(trim($Human_check_1)) == "seven") { // strtolower - Returns string with all alphabetic characters converted to lowercase $validationOK=TRUE; // If Human_check_1 equals either 7 or seven validation passes } $validationOK=false; if (strtolower(Trim($Human_check_2)) == "orange") { $validationOK=true; // If Human_check_2 is equal to orange validation passes } if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } Please somebody point me in the right direction Thanks Jay Link to comment https://forums.phpfreaks.com/topic/178768-help-please-how-to-validate-from-2-possible-answers/#findComment-944036 Share on other sites More sharing options...
jay4708 Posted October 28, 2009 Author Share Posted October 28, 2009 Hi again, I'm still having trouble getting my head round the above code, could somebody please take a look to see what's wrong. Thanks Jay Link to comment https://forums.phpfreaks.com/topic/178768-help-please-how-to-validate-from-2-possible-answers/#findComment-946593 Share on other sites More sharing options...
M.O.S. Studios Posted October 28, 2009 Share Posted October 28, 2009 goto http://recaptcha.net it is ment to stop spam and you can add it to your form. also it helps copy books into digital form Link to comment https://forums.phpfreaks.com/topic/178768-help-please-how-to-validate-from-2-possible-answers/#findComment-946600 Share on other sites More sharing options...
mrMarcus Posted October 28, 2009 Share Posted October 28, 2009 you keep throwing in $validationOK=false; and $validationOK=true; every so often. you're confusing the life out of the script. it also appears that you might ('cause i'm not sure since you haven't posted the entire code), have register_globals turned on. you should really turn that off. and i'm sorry, you're going to have to be a little more specific as to the issue .. don't have the time right now to really try and figure out the problem. what do you mean "it stops working" .. gotta be more specific than that. can you post your form code too please? Link to comment https://forums.phpfreaks.com/topic/178768-help-please-how-to-validate-from-2-possible-answers/#findComment-946609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.