I am currently working on some additional form validation in the model's beforeValidate() .
I have the following code:
function beforeValidate(){ $i = 0; foreach($this->data['CapitalCategory'] as $capital_category){ if(!empty($capital_category['value'])){ $this->invalidate('CapitalCategory.'.$i.'.points', 'error!'); return false; } $i++; } return true; }
I debugged everything and it returns false if value is present. But then the form reloads, and no messages are displayed below the entered points! Also, if I debug validationErrors , the array contains an error that should be displayed. What could be the problem?
Appreciate any help!
EDIT
This is how I build my inputs:
echo $this->Form->input('CapitalCategory.'.$i.'.value', array('label' => $category['Category']['name'], 'type' => 'text')); echo $this->Form->input('CapitalCategory.'.$i.'.points', array('label' => 'Puncte', 'type' => 'text'));
I believe that the problem may be that I am working on a CapitalModel in which, in addition to some fields of CapitalModel, I used several fields from my sister model CapitalCategorieModel. Could this be a problem for not associating a validation error with a field? If so, how can I solve it?
validation cakephp
linkyndy
source share