Re: validates() not working on all functions...

2009-07-30 Thread number9

Thanks for the reply, that makes sense.

I actually ended up going with a more robust image upload component
that has sorted the validation issues.

On Jul 28, 11:57 am, delocalizer  wrote:
> 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  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 invalidationfor 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 imagefield(Img.pic) on another function (/
> > edit_image/) thevalidationfunction 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: validates() not working on all functions...

2009-07-28 Thread delocalizer

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  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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



validates() not working on all functions...

2009-07-27 Thread number9

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---