Suppose the email field is empty.
Array
(
[Comment] => Array
(
[post_id] => 10
[name] => name6
[email] =>
[body] => body6
)
)
This is the add action.
function add($id) {
$temp = $this->data;
debug($temp);
if (!empty($this->data)) {
$this->Comment->create();
if ($this->Comment->save($this->data)) {
$this->Session->setFlash('Your comment has been saved.');
$this->redirect(array('controller'=>'posts','action' => 'index'));
}
}
}
Now how can i开发者_如何转开发 check whether the email field empty or not. If any field is empty then it will display message and redirect to another action.
function add($id) {
if(!isset($this->data['Comment'][email]))
{
$this->Session->setFlash('Email is empty. Please try again !!');
$this->redirect(array('controller'=>'posts','action' => 'index'));
}
Your add code goes here...
But i suggest you to put all validation in respective model.
精彩评论