CakePHP saves validation errors after redirection

I have an element that displays a comment form, the action is comments / adding. If the form is not validated, I do not want users to switch to comments / additions (for which a presentation does not exist), but I want them to stay on the same page and see validation errors there.

However, redirecting to $ this-> referer () does not work - verification errors disappear and only the flash message remains.

public function add(){
    if (!empty($this->data)){
        $this->Comment->create();
        if ($this->Comment->save($this->data)){
            $this->Session->setFlash('Comment added.','success');
            $this->redirect($this->referer());
        }else{
            $this->Session->setFlash('There was a problem adding your comment.  Please try again.','failure');
        }
    }
}

How can I either save validation errors and generate data for redirection? If this is not possible, how else can I solve the problem?

Many thanks,

Will

+3
source share
2 answers

$this- > redirect ($ this- > referer()); .

, , ? save() , , , db .

0

All Articles