Are you setting your data to the model in the controller action before validating/saving? $this->Model->set($this->data); $this->Model->save(); etc.
On Jul 28, 12:27 am, number9 <[email protected]> wrote: > I'm using a validates function in a model in order to validate image > uploads. I want to validate the filetype, and also make it required. > > I know cake has built in validation for these, but I could never get > it to work. The image upload component I am using uses an array, > accessible via $this->data['Img']['pic']. > > The problem I am having, is that the /add/ function works great, but > when I use the image field (Img.pic) on another function (/ > edit_image/) the validation function isn't applied. > > Here is the model code: > > function validates() > { > > $image = $this->data['Img']['pic']['name']; > // Grab the file extension: > $path = pathinfo($image); > $filetype = $path['extension']; > > if(!empty($image)) { > > if (($filetype != 'JPG') && ($filetype != 'jpg') && > ($filetype != > 'GIF') && ($filetype != 'gif') && ($filetype != 'JPEG') && ($filetype ! > = 'jpeg')) > { > $this->invalidate('Img.pic'); > } > } > else { > $this->invalidate('Img.pic'); > } > > $errors = $this->invalidFields(); > return count($errors) == 0; > } > > Is there something I have to include in the controller to make the > above happen automatically? > > I would appreciate any guidance on this, I can include more code if > requested. > > Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
