CakePHP保存重定向后的验证错误 [英] CakePHP preserving validation errors after redirecting
本文介绍了CakePHP保存重定向后的验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个元素显示一个注释形式,动作是comments / add。如果表单不验证,我不想让用户去评论/添加(不存在的视图),但我希望他们保持在同一页面,并看到验证错误。
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.
但是,重定向到$ this-> referer()不起作用 - 验证错误消失,只剩下闪存消息。
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?
非常感谢,
推荐答案
这篇关于CakePHP保存重定向后的验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文