Page 1 of 1

Unable to get a piece of code to execute

Posted: Fri Jun 02, 2006 5:57 am
by mcccy005
Sorry about the vague title but I didn't know what else to write.
Basically I have written an input field class with text_field; select_field etc. extending it.
In the parent input_class is a method called "is_valid( )" which tests whether the data entered into the field is valid based on whether the data is of type "string", "numeric", "abn" (AUstralian Business Number), "email", "state" etc.

If I set the data type to any of the above I can get it to work EXCEPT for a data of type "state".
Here is some code:

Code: Select all

if($this->data_type=="state")
{	
	echo "Line 85";
	if(validate_state($_REQUEST[$this->field_name])) return true;
	else return false;
}
Now I can get "Line 85" to print no worries.
However, if I go into the function "validate_state( )", I can't get even the first line ("Test") to print out.
Eg.

Code: Select all

private function validate_state($state)
{
	/*Creates an array storing all the states and territories of Australia */
                echo "Test";
	$states=array("SA", "NSW", "VIC", "QLD", "NT", "WA", "TAS", "ACT");
	for($i=0; $i<sizeof($states); $i++)
	{	if ($state==$states[$i])
		return true; //Returns true if $state is equal to any state within the $states array
	}
	return false; //Returns false if $state does not match any of the states within the $states array
}


the word "Test" won't print out at all to which I'm buggered if I can work out why??
This function seems to work fine: (yep its a dodgy way to check validity of email I know but it does enough)

Code: Select all

private function validate_email($email)
{
	if(!strstr($email, "@") || !strstr($email, ".")) return false;
	else return true;
}

Sorry about all the excess code but hopefully someone can work out what is going wrong.

Posted: Fri Jun 02, 2006 6:22 am
by JayBird
Shouldn't it be

Code: Select all

if($this->validate_state($_REQUEST[$this->field_name])) return true;

Posted: Sat Jun 03, 2006 8:34 pm
by mcccy005
Hmm.....yes it should be. I SWEAR i tried that and it wouldnt work?????
Thanks for that.