dc_jt Posted October 18, 2006 Share Posted October 18, 2006 HiIm trying to validate the name field so that no numbers can be inputted. Here is my function in my Clients table class:[code]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); } }?>[/code]I then have a globals file which contains the 'validatename' function:[code]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);}[/code]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 35Anyone know why?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/ Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 Anyone?? :'( Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110621 Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 Can you provide all of the code for the page that's causing issues.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110630 Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 [code]<?phprequire_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); } }?>[/code]Line 35 which is below is whats causing the problem:if(validatename($aPostData['Name'])===false) Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110631 Share on other sites More sharing options...
printf Posted October 18, 2006 Share Posted October 18, 2006 You say you have global file, so are you saying those functions (validateemail, validate_name, validate_email) are not methods in your class?me! Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110633 Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 ***Edited - Wrong file*** Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110636 Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 You're problem is here:[code]if(validatename($aPostData['Name'])===false)[/code]You're function is called "validate_name" not "validatename". Correction:[code]if(validate_name($aPostData['Name'])===false)[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110640 Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 That's not the problem, there's two functions, one called [color=green]validatename()[/color] and the other called [color=green]validate_name()[/color]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110641 Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 There actually isn't any function called validatename in his code at all. Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110645 Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 My mistake I posted the wrong global above. Here is the correct one:[code]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);[/code]So I do have a validatename function Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110646 Share on other sites More sharing options...
HuggieBear Posted October 18, 2006 Share Posted October 18, 2006 I was looking at the code at the top of the page, I know I'd seen it somewhere.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110653 Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 removed because of something stupid Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110657 Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 I think I found it...[code]<?phpfunction 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 MISSINGfunction 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?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110659 Share on other sites More sharing options...
dc_jt Posted October 18, 2006 Author Share Posted October 18, 2006 What a fool I am!!Thanks a lot for spotting thatMuch appreciated :) Quote Link to comment https://forums.phpfreaks.com/topic/24315-call-to-undefined-function-validatename-in/#findComment-110660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.