CakePHP validation not working

后端 未结 3 782
挽巷
挽巷 2021-01-22 08:13

Iam new in cakephp ,I need to validate a form.

This is the code: Controller:



        
3条回答
  •  囚心锁ツ
    2021-01-22 08:44

    CakePHP is designed to automatically validate model and display validation errors. Auto validation runs on model save. In your case:

    $this->Task->save($this->request->data);
    

    above will trigger validation. There is no need to run: $this->Task->validates() - If you do so, you also have to take care of displaying validation error by your own. So I think you simply should try:

    request->is('post')) {
          // If the form data can be validated and saved...
          if ($this->Task->save($this->request->data)) {
             //saved and validated
          }
        }
      }
    }
    ?>
    

提交回复
热议问题