«
»

archived blog posts

Confusing cakephp validation rule ‘required’=>true

11.18.08 | Comment?

I want to clarify the usage of ‘required’=>true in cakephp as a validation rule to your forms.

When using this rule, you must not confuse yourself with the other validation rule ‘notEmpty’ as told by teknoid. And from the cookbook it says,

This key should be assigned to a boolean value. If ‘required’ is true, the field must be present in the data array.

What it simply means (to my understanding), is that that field as key of data array in your Model must exist, or it will fail.

Don’t ever forget to include this line of code before the Model::Validates() method:

$this->Users->set($this->data);

If it still fails, try checking the $data array of your Model in Model::beforeValidate() method:

function beforeValidate() {
pr($this->data);
}

Just to see what your data array looks like before data validation.

Tags:

Comments are closed.


«
»