Thanks. That's exactly what I had in mind, just couldn't figure out how to catch the errors. It's a bit of work, just to display errors, but it will work for now.
On Oct 23, 2:30 pm, Céryl <[email protected]> wrote: > I struggled with this, excactly this week! I'm doing it by heart right > now, but I guess you can guess the gist of it. > Basicly, build the add form at page that you want. Use the > $form->create('Model', array('url' => '/controller/add')) to redirect to the > > add action of the controller you want after the button-click... > > Then to catch and display the validation-errors (assuming you set them > in your Model), in the add function do this: > > if ($this->Model->save($this->data)) { > $this->Session->setFlash('Thing stored');} else { > > if (!empty($this->Model->validationErrors)){ > //Validation error, display errors in Session->Flash() > $errors = $this->Product->validationErrors; > foreach($errors as $error): > $errortext .= '- '.$error.'<br />'; > endforeach; > $this->Session->setFlash($errortext); > } else { > //Not stored, but no validation errors, probably a > database problem > $this->Session->setFlash('Database Problem'); > } > > } > > Then redirect to the add/index-page and it'll display the validation > errors (The text you stored in the model) in a list in the session- > > >flash, just make sure you display that... > > Hope it helps! > > On 23 okt, 19:58, "[email protected]" <[email protected]> > wrote: > > > I figured I can just do a redirect() but I can't figure out how to > > pass the validation errors along. Anyone? > > > On Oct 23, 1:18 pm, "[email protected]" <[email protected]> > > wrote: > > > > Ok, > > > > Here's the situation: > > > > I have a page that allows users to post comments, but this is not a > > > ADD page... > > > > when I create the add() function in the CommentController it > > > automatically looks for a add.ctp because it assumes that's where my > > > form was. All the data gets saved, but it doesn't know where to > > > redirect to... > > > > How can I skip the add view? I don't want to create an Add view just > > > to post a comment's form. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
