CakePHP : Validation message not displaying

前端 未结 3 1514
暗喜
暗喜 2021-02-06 17:19

I\'m new to cakePHP and I\'ve made a simple form following some tutorial. On this html form I\'ve used validation. Now the problem is that the validation is working but the mess

3条回答
  •  -上瘾入骨i
    2021-02-06 17:57

    Your Form-create() options are invalid, first argument is the model-name, second is for options:

    Add New Post

    Form->create('Post', array('action'=>'add')); echo $this->Form->input('title'); echo $this->Form->input('body'); echo $this->Form->end('Create Post'); ?>

    If the form-helper does not know which 'model' it is creating a form for, I won't check for field validation in the right place, hence, it won't output the validation errors for 'title'

    [update] solution above didn't solve the problem. OP has modified the question

    Some ideas:

    1. Be sure to enable 'debug' (App/Config/core.php set Configure::write('debug', 2); Otherwise CakePHP may be using a 'cached' version of your model.

    2. If you've named your Model incorrectly, Cake may be automatically generating a model for you, in which case your own model is never actually used, try this for debugging to see if we even 'get' to your model:

    Add this to your model;

    public function beforeValidate($options = array())
    {
         debug($this->data); exit();
    }
    

提交回复
热议问题