Jump to content

Help please - How to validate from 2 possible answers


jay4708

Recommended Posts

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

 

 

 

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

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?

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.