Jump to content

Archived

This topic is now archived and is closed to further replies.

dc_jt

Call to undefined function validatename() in

Recommended Posts

Hi

Im 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 35

Anyone know why?

Thanks

Share this post


Link to post
Share on other sites
Can you provide all of the code for the page that's causing issues.

Regards
Huggie

Share this post


Link to post
Share on other sites
[code]<?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);
}


}
?>[/code]

Line 35 which is below is whats causing the problem:

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

Share this post


Link to post
Share on other sites
You say you have global file, so are you saying those functions (validateemail, validate_name, validate_email) are not methods in your class?


me!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
That's not the problem, there's two functions, one called [color=green]validatename()[/color] and the other called [color=green]validate_name()[/color]

Regards
Huggie

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I was looking at the code at the top of the page, I know I'd seen it somewhere.

Regards
Huggie

Share this post


Link to post
Share on other sites
I think I found it...

[code]

<?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

?>

[/code]

Share this post


Link to post
Share on other sites
What a fool I am!!

Thanks a lot for spotting that

Much appreciated

:)

Share this post


Link to post
Share on other sites

×

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.