我需要返回表单验证,因为我在提交后丢失了它
我在 News/view/30 ---查看报告详细信息---在该页面中,我们添加了评论表单:
<h2>Add comment</h2>
<?php
echo $this->Form->create("Comment", array(
'url' => array('controller' => 'Comments', 'action' => 'add')
));
echo $this->Form->label("name");
echo $this->Form->input("name", array("label" => false, "class" => "textfield"));
echo $this->Form->label("email");
echo $this->Form->input("email", array("label" => false, "class" => "textfield"));
echo $this->Form->label("text");
echo $this->Form->textarea("text", array("label" => false));
echo $this->Form->input("object_id", array("type" => "hidden", "value" => $data['News']['id']));
echo $this->Form->input("type", array("type" => "hidden", "value" => "news"));
echo $this->Html->Link("Add Comment", "#", array("class" => "add_button", "onclick" => "$('#CommentViewForm').submit()"));
echo $this->Form->end();
?>
表单在评论控制器上提交:
在评论/添加:
$isSuccess = $this->Comment->save($this->request->data);
if ($isSuccess) {
$this->Session->setFlash('your Comments has been added successfully and pending admin aproval.thanks ', 'default', array(), 'good');
} else {
$this->Session->setFlash('Failed to add your comment: <br/>Fill all the required fileds <br/>type correct Email', 'default', array(), 'bad');
}
$this->redirect(array("controller" => "News", "action" => "view", $id));
当用户输入有错误返回添加评论表单但没有像往常一样显示错误时,我对姓名、电子邮件和评论本身做了一些验证规则
我希望你能很好地理解我,我等待你的帮助非常感谢