I have an element which displays a comment form, the action is comments/add. If the form doesn't validate, I don't want users to go to comments/add (the view for which does not exist), but I want them to remain on the same page and see the validation errors there.
However, redirecting to $this->referer() doesn't work - the validation errors disappear and just 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 retain the validation errors and form data on redirect? If this isn't possible, how else can I solve the problem?
Thanks a lot,
Will