I think we have a misunderstanding. The code I sent you was for your model. The only thing that changes was you had some code in the "afterValidate" function and I provided you with an alternative to do all the legwork in the "beforeValidate" function.
If you use "beforeValidate" you can do all the photo uploading and field-setting logic and return TRUE. Alternatively, you can return FALSE to prevent further validation if there is an error. *NOTE: If *beforeValidate* returns FALSE CakePHP will short-circuit and "* validates()*" DOES NOT execute. * *NOTE: If *beforeValidate* returns TRUE CakePHP will execute "*validates()*". **Performing the file upload in the *afterValidate* function is TOO LATE; The Model has already attempted to validate your field "*photo*" and the error is already set before *afterValidate* callback event is executed.* *NOTE: The function **afterValidate** is called by the ModelValidator object inside the **errors* * function. The ModelValidator **errors** function performs tests all the fields, sets errors, and finally executes * afterValidate* before returning.* SEE: http://book.cakephp.org/2.0/en/models/callback-methods.html Sincerely, Charles A Beasley On Sun, Mar 1, 2015 at 5:56 AM, Sam Clauw <[email protected]> wrote: > Charles, thank you for the great effort! > But is there no other option than move the validation into the controller > instead of doing it in the model? > > The code I wrote only contains one single if/else and is very clear to me. > Okay, it's not working so I'm not getting anywhere for the moment huh ;) > > Can you confirm that extension rule in CakePHP is validation the ['type'] > variable in the FILES array? If "yes", I realy don't understand why I keep > getting validation errors on the validExtension rule :s > > -- > Like Us on FaceBook 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 unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Like Us on FaceBook 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 unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
