The flow is beforeValidate -> validate -> beforeSave -> save First beforeValidate() callback is to check data and make global decision go further / this data cannot be validated/saved. If answer is no save() immediately returns false. If beforeValidate() was successful actual validation occurs. If it fails save() returns false. If validation sucseed, beforeSave() is called. Here you can as modify data if you want some fields go to DB in other format that user entered as make some additional validation. Again, you can return false and abort save. Only if beforeSave() was successful actual save takes place.
So callbacks named exactly as they behave. On Mar 13, 4:04 am, "Dave" <[email protected]> wrote: > Most tutorials or tips online refer to before Save () as a good before > saving to clean data and what not but never have i seen anything on > beforeValidate as beforeValidate seems to be better to use i would think. > No? > > For example city has validation rules say min 5 characters if someone enters > "<p>b</p>" into the city field that meets the minimum 5 character yes then > you beforeSave clean out the html so you left with "b" as the city name yet > thats not 5 charaters you were wanting to ensure. so you save "b" as the > city name > > Is it not best to say use beforeValidate to clean up your data make sure it > meets validation if so then do your beforesave on that data? > > I was using beforeSave and noticed i could trick cake into thinking it was > ok and could actually just put html tags into fields to meet min > requirements, a-z-0-9 and actually save an entire form record and every > field inthe db was completely blank because it said it was valid and the > data that was safe to save was actually nothing yet i set up notempty => > true. > > Any thoughts? > > Dave Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
