Thursday, October 29, 2009

Re: How to retrieve validation errors on model save?

Do not use invalidFields(), just use:

$this->Model->validationErrors;

invalidFields() causes your validation to run twice, which causes
problems in some cases.

On Oct 29, 5:50 pm, igotskils <traedama...@googlemail.com> wrote:
> On 29 Okt., 22:08, Will Poillion <lorew...@gmail.com> wrote:
>
>
>
> > Simple question:
>
> > I'm attempting to save a model, and the data to be saved is not
> > passing the validation rules. How do I retrieve the validation error?
>
> > if ($this->Ingredient->IngredientImage->save($this->data)) {
> >         //success
> > $this->Session->setFlash(__('The Ingredient Image has been saved',
> > true));} else {
>
> >         // retrieve validation error and return to view
>
> > }
>
> > Also, am I correct in assuming that setFlash is useless in an ajax
> > call? I know I'm a noob but I'm not sure how I would use the setflash
> > and flash functionality in an ajax call. Any clue as to how to do this
> > would be most appreciated.
>
> > Thanks!
> > Will
>
> ajax? don't no what you mean with that here but i would try:
>
> $this-set('validtionErrors',$this->Ingredient->IngredientImage-
>
> >invalidFields());
>
> (dont forget the search function of the cookbook ;) )
>
> matic
--~--~---------~--~----~------------~-------~--~----~
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 cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: