Jump to content


Photo

Call to undefined function validatename() in


  • Please log in to reply
13 replies to this topic

#1 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 10:45 AM

Hi

Im trying to validate the name field so that no numbers can be inputted. Here is my function in my Clients table class:

private function ValidateClientData($aPostData)
	{
		$aErrors = array();
	
		if(validatename($aPostData['Name'])===false)
		{
			$aErrors['Name']='Please enter your Name';}
		
		if(validateemail($aPostData['Email'])===false)
		{
			$aErrors['Email']='Please enter a valid Email address';}
		//if(validateemail(!$aPostData['Email'])===false)
		//{
		//	$aErrors['Email']='Please enter your Email';
		//}
		if(!$aPostData['Address'])
		{
			$aErrors['Enquiry']='Please enter your Address';
		}	
		if(!$aPostData['Business_Name'])
		{
			$aErrors['Business_Name']='Please enter your Business Name';
		}
		if(!$aPostData['Type_of_Business'])
		{
			$aErrors['Type_of_Business']='Please enter your Type of Business';
		}
		
		
		if (count($aErrors) > 0) return array(false, $aErrors);
		
		return array(true);
	}
	
	
}
?>

I then have a globals file which contains the 'validatename' function:

function validate_email ($email) 
{
	if(ereg('^[_a-z0-9A-Z+-]+(\.[_a-z0-9A-Z+-]+)*@[a-z0-9A-Z-]+(\.[a-z0-9A-Z-]+)*$', $email)) 
	{
		return true;
	}
   	else 
	{
    	return false;
	}
}

function validateemail ($email) 
{
	return validate_email($email);
	
function validate_name ($name)
{
	if(ereg("/^[a-zA-Z\-\Ä\ä\Ö\ö\Ü\ü\s]+$/s", $name))
	{
		return true;
	}
   	else 
	{
    	return false;
	}

}
function validatename ($name) 
{
	return validate_name($name);
}

As you can see its exactly the same as the email function except the characters that are accepted.

I get the error
Fatal error: Call to undefined function validatename() in /mnt/k/*****/website/_lclasses/Tables/RCLTblClients.class.php on line 35

Anyone know why?

Thanks

#2 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 12:45 PM

Anyone??  :'(

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 October 2006 - 12:55 PM

Can you provide all of the code for the page that's causing issues.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 12:58 PM

<?php

require_once(LOCAL_CLASSES.'/RCLDbBase.class.php');
require_once(GLOBALS.'global_fns.php');

class RCLTblClients extends RCLDbBase

{
	protected $sTableName = "clients";
	
	public function AddClient($aPostData)
	{	
		$aReturn = $this->ValidateClientData($aPostData);
		
		if (!$aReturn[0])
		{		
			return $aReturn;		
		}
		
		$sSql = "INSERT INTO $this->sTableName SET 
				name = '$aPostData[Name]', 
				email = '$aPostData[Email]',
				address = '$aPostData[Address]',
				business_name = '$aPostData[Business_Name]',
				type_of_business = '$aPostData[Type_of_Business]',
				comments ='$aPostData[Comments]' ";
		
		return array(mysql_query($sSql, $this->oDb->GetConnection()));
	}
	
	private function ValidateClientData($aPostData)
	{
		$aErrors = array();
	
		if(validatename($aPostData['Name'])===false)
		{
			$aErrors['Name']='Please enter your Name';}
		
		if(validateemail($aPostData['Email'])===false)
		{
			$aErrors['Email']='Please enter a valid Email address';}
		//if(validateemail(!$aPostData['Email'])===false)
		//{
		//	$aErrors['Email']='Please enter your Email';
		//}
		if(!$aPostData['Address'])
		{
			$aErrors['Enquiry']='Please enter your Address';
		}	
		if(!$aPostData['Business_Name'])
		{
			$aErrors['Business_Name']='Please enter your Business Name';
		}
		if(!$aPostData['Type_of_Business'])
		{
			$aErrors['Type_of_Business']='Please enter your Type of Business';
		}
		
		
		if (count($aErrors) > 0) return array(false, $aErrors);
		
		return array(true);
	}
	
	
}
?>

Line 35 which is below is whats causing the problem:

if(validatename($aPostData['Name'])===false)

#5 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 18 October 2006 - 01:00 PM

You say you have global file, so are you saying those functions (validateemail, validate_name, validate_email) are not methods in your class?


me!

#6 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 01:04 PM

***Edited - Wrong file***

#7 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 18 October 2006 - 01:11 PM

You're problem is here:
if(validatename($aPostData['Name'])===false)

You're function is called "validate_name" not "validatename". Correction:

if(validate_name($aPostData['Name'])===false)

SA PHP Archives - www.phparchives.za.org

#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 October 2006 - 01:13 PM

That's not the problem, there's two functions, one called validatename() and the other called validate_name()

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#9 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 18 October 2006 - 01:17 PM

There actually isn't any function called validatename in his code at all.
SA PHP Archives - www.phparchives.za.org

#10 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 01:19 PM

My mistake I posted the wrong global above. Here is the correct one:

function validate_email ($email) 
{
	if(preg_match('^[_a-z0-9A-Z+-]+(\.[_a-z0-9A-Z+-]+)*@[a-z0-9A-Z-]+(\.[a-z0-9A-Z-]+)*$', $email)) 
	{
		return true;
	}
   	else 
	{
    	return false;
	}
}

function validateemail ($email) 
{
	return validate_email($email);
	
function validate_name ($name)
{
	if(ereg("/^[a-zA-Z\-\Ä\ä\Ö\ö\Ü\ü\s]+$/s", $name))
	{
		return true;
	}
   	else 
	{
    	return false;
	}

}
function validatename ($name) 
{
	return validate_name($name);

So I do have a validatename function

#11 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 18 October 2006 - 01:25 PM

I was looking at the code at the top of the page, I know I'd seen it somewhere.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#12 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 18 October 2006 - 01:33 PM

removed because of something stupid
SA PHP Archives - www.phparchives.za.org

#13 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 18 October 2006 - 01:38 PM

I think I found it...


<?php

function validate_email ($email) 
{
	if(preg_match('^[_a-z0-9A-Z+-]+(\.[_a-z0-9A-Z+-]+)*@[a-z0-9A-Z-]+(\.[a-z0-9A-Z-]+)*$', $email)) 
	{
		return true;
	}
   	else 
	{
    	return false;
	}
}

function validateemail ($email) 
{
	return validate_email($email);
} // THIS WAS MISSING

function validate_name ($name)
{
	if(ereg("/^[a-zA-Z\-\Ä\ä\Ö\ö\Ü\ü\s]+$/s", $name))
	{
		return true;
	}
   	else 
	{
    	return false;
	}

}

function validatename ($name) 
{
	return validate_name($name);
} // THIS WAS MISSING

?>


SA PHP Archives - www.phparchives.za.org

#14 dc_jt

dc_jt
  • Members
  • PipPipPip
  • Advanced Member
  • 290 posts

Posted 18 October 2006 - 01:40 PM

What a fool I am!!

Thanks a lot for spotting that

Much appreciated

:)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users