have you ever seen validates() taking arguments? especially $data? nope $this->Model->set($this->request->data) $result = $this->Model->validates()
as the book describes Am Sonntag, 16. September 2012 20:09:24 UTC+2 schrieb resting: > > Created a test setup with v2.2.0 > > Validation doesn't work. > Empty fields still pass. > > What am I doing wrong here? > > Full source: > https://github.com/resting/cakephp/blob/test_validation/app/Controller/MyFormController.php > > On Friday, 14 September 2012 15:42:36 UTC+8, resting wrote: >> >> I have something like this in my view: >> >> echo $this->Form->input('Modelname.1.fieldname'); >> >> (ref: >> http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#field-naming-conventions) >> >> >> >> I have this in my model: >> >> public $validate = array( >> 'filename' => array('ruleFilenameEmpty' => array('rule' => >> 'notEmpty', 'required' => true, 'allowEmpty' => false, 'last' => true))); >> >> This is the structure of $this->request->data: >> >> array( >> 'Capture' => array( >> (int) 0 => array( >> 'filename' => '', >> ) >> ) >> ) >> >> But it always return a validation error, whether there's text in the >> textfield or not: >> >> array( >> 'filename' => array( >> (int) 0 => 'ruleFilenameEmpty' >> ) >> ) >> >> (printed from debug($this->Capture->validationErrors)) >> >> Tested the validation with: >> >> $this->Capture->set($this->request->data); >> if ($this->Capture->saveAll($this->request->data)) { >> $this->Session->setFlash('<span style="color: red">' . __('It >> validates') . '</span>'); >> } >> >> I had tried all possible names for the validation. None works. >> >> What am I doing wrong here? >> >> Also I would like to validate each set of fields in $this->request->data >> before saving. >> >> This is because there are some others to be done after it validates. >> If the action fails, it should not save. >> This cannot be done with saveAll(). >> >> How can I evaluate each set of arrays in $this->request->data before >> saving? >> > -- Like Us on FacekBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en.