开发者

CakePHP question: How can i check whether there is an empty field or not after submitting form?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜