Rather than trying to return an error message from your validation
functions, split up your validation into smaller single purpose
validations.
Each smaller validation method can be assigned a message to report on
failure.
$validate = array(
'field_name' => array(
'length' => array(
'rule' => 'vLength',
'message' => 'Length does not meet requirements'
),
'characters' => array(
'rule' => 'vAllowedCharacters',
'message' => 'Only certain characters are allowed'
),
'something' => array(
'rule' => 'vSomethingElse',
'message' => 'Something Else is wrong.'
)
)
);
function vLength($data) {
/// -- implementation
}
function vAllowedCharacters($data) {
/// -- implementation
}
function vSomethingElse($data) {
/// -- implementation
}
Cheers,
Graham Weldon
e. [email protected]
p. +61 407 017 293
w. http://grahamweldon.com
On 27/08/2009, at 2:08 PM, JamesF wrote:
>
> var $validate = array(
> 'username' => array(
> 'customFunction' => array('rule'=>
> 'customFunction',
> 'message'=>'user name error', ),
> ),
> );
>
> function customFunction($data) {
>
> if($data['username'] == $someConditions) {
> return true;
> }
> else if ($data['username'] == $someOtherConditions) {
>
> return false;
> }
> //otherwise failed
> return false;
> }
>
> instead of return false can i return the specific reason why it failed
> in the form of an error message?
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---