To ensure that both models show validation errors, just call
validates() manually (which will in turn invalidate() each field that
does not match).
$this->User->set( $this->data );
$this->Profile->set( $this->data );
$user_validates = $this->User->validates();
$profile_validates = $this->Profile->validates();
if ( $user_validates && $profile_validates ){
// ok to proceed, save both models
} else {
// validation error, show form again
}
Perhaps explain more about what this custom validation entails. If
possible, all validation should be done in the model files themselves
(in beforeValidate() ), so the above code would work fine. But
otherwise, you can always have whatever you like, and just call
something like $this->User->invalidate('name', 'That name is silly');
On Dec 16, 7:15 pm, AussieFreelancer <[EMAIL PROTECTED]>
wrote:
> Hi All,
>
> I have 2 tables, users and profiles. Along with those I have 2 models,
> and in those models I have some validation rules.
>
> When I submit a form that has fields for User and Profile on it, the
> User is validated first. If a required field is empty, obviously cake
> stops processing it and sends you back to show the errors.
>
> But I would like to validate both the User and Profile models, then
> return error messages for all the fields with errors - not just from
> the one model. How can I do this?
>
> Also in the same form, I have some fields that I join before saving,
> so I will need custom validation going on there. My controller doesn't
> have a specific model, it uses User and Profile instead. How can I
> validate this field and return the error message at the same time?
>
> Thanks
>
> Patrick
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---