> Yes several rules per field was the way to go
>
> But my custom validation would contact a remote server and then
> display an error message appropriately
>
> So I thought I would save on those remote calls if for single
> validation rule I had the facility for displaying different error
> messages
>
> Also I tried $this->invalidate('field', 'Error message') in my custom
> validation function but only the default error message still displays

If you will invalidate field val1 from inside validation method val1()
AND return false, your custom message will be overwritten with default
one, specified in your validation rule. You might want to implement
beforeValidate() callback in your model instead of validation rule,
like:

function beforeValidate() {
    if (....your condition....) {
        $this->invalidate('val1', 'Custom error message');
        return false;
    }

    return true;
}

With this code, and
    echo $form->input('val1'); // field input and error
or
    echo $form->error('val1'); // field error
in view, your custom error message will be displayed.

> P.S as an added note can you please post an example with custom
> validation where the error message is in the VIEWS and NOt in the
> MODEL ?

http://book.cakephp.org/view/198/options-error
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to