Unable to get a piece of code to execute

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Unable to get a piece of code to execute

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Shouldn't it be

Code: Select all

if($this->validate_state($_REQUEST[$this->field_name])) return true;
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Post by mcccy005 »

Hmm.....yes it should be. I SWEAR i tried that and it wouldnt work?????
Thanks for that.
Post Reply