Jump to content

Call to undefined function validatename() in


dc_jt

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
[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)
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
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]

Archived

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

×
×
  • Create New...

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.