开发者

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

开发者 https://www.devze.com 2023-04-04 07:45 出处:网络
Suppose the email field is empty. Array ( [Comment] => Array ( [post_id] => 10 [name] => name6 [email] =>

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

精彩评论

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