Jump to content

Form validation problems


TrueColors

Recommended Posts

I have Gender, Date of Birth, and Captcha validations. Though they are not working.

 

Lets start with gender. Then captcha, then DOB.

 

I call the Gender check via doing if(user::isValidGender($this->gender) == FALSE) $errors[] = "Invalid gender";

"user" is another class.

 

The function isValidGender() is as follows

    public function isValidGender($gender)
    {
        $validGenders = array("male", "female", "mtf", "ftm", "androgyne", "intersex");
            
        if(in_array($gender, $validGenders) == FALSE) return false;
    }

 

When I do if(in_array($gender, $validGenders) == FALSE) die("error"); it doesn't die. It displays "Invalid Gender" which means that if it doesn't do the die() it returns true. Though it checks if the function returns false when calling "isValidGender()".

 

If I put the die() above the if, it dies. So it obviously is returning true, but why is it displaying the error?

Link to comment
https://forums.phpfreaks.com/topic/218689-form-validation-problems/
Share on other sites

Thanks thorpe that worked! Can you explain why my original method didn't work?

 

- My next problem is the captcha.

md5($captcha) is 706a335b65ce9ccabd6c683b2dec13d2

$_SESSION['ckey'] is 706a335b65ce9ccabd6c683b2dec13d2

(I echo'd them both out and they are exact)

 

I call the function by doing this if(user::isValidCaptcha($this->captcha) == FALSE) $errors[] = "Your captcha image was incorrect!";

The function is

public function isValidCaptcha($captcha)
{
	die(md5($captcha) . '<br />' . $_SESSION['ckey']); // This was to test and both results were the same

	if(md5($captcha) != $_SESSION['ckey']) return false;
}

 

Even though both are the same, why does it display the error that it's incorrect?

return ((md5($captcha) == $_SESSION['ckey']) ? true : false);

That method works.

 

Again I ask, along with my previous issue: Why did it not work the way I had coded it?

 

My next issue, which is slightly different. Is for DOB. I call it the same way and this is the function

	public function isValidDOB($day, $month, $year)
{
	if(($day > 31 || $day < 01) || ($month > 12 || $month < 1) || ($year >= date('Y', time()) || $year <= 1910))
	{
		return false;	
	}
}

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.