Can you tell us more about why you need warnings? The simplest alternative might be a completely alternate approach.
-- John On Jan 25, 2008, at 8:19 AM, grigri wrote: > > I am using 1.2 (have been for a while), and I'm very impressed by its > validation system. But I can't see how I can do what I need without > more code. I'll try and explain. > > The basic system of "warnings" could be implemented by having a > beforeValidate() method (in a Behavior or Model) which enumerates the > $validate array [*], checks for entries with a specific option (such > as 'warning' => true), then cross-checks that against a different key > in the data (corresponding to the 'ignore warning' checkbox), and if > present, temporarily removes it from the validation array (setting > 'on' to any value other that 'create', 'update' or null would > accomplish this). > > [ * The orderings of validation and warning entries would be crucial > for this to work properly, because an error must always override a > warning. ] > > At this point, it can flag the field as failing, but when the form > helper outputs the error message, I need it to output an extra > checkbox dynamically with a specific name and value. Although I could > code this directly in the beforeValidate() [a bit messy, but still > possible], the FormHelper::input() method, when calling > FormHelper::error(), ALWAYS escapes the HTML, so I'd be rendering HTML > code not real working HTML. > > I could of course code the "error message" in a specific way (like > "{{{WARNINGDATA:encoded_data_here}}}") then do a preg_replace_callback > in a helper afterRender() method, but it's quite a messy way of doing > things, with a possible performance hit. Plus I'd have to add the > helper in the controller; which should really be agnostic to this > information. > > I'm wondering if I'm making this more complicated than it needs to be. > Based on what I've explained I'd like to achieve, can you see a > different (possibly simpler) way of doing it? > > Thanks > > On Jan 25, 2:20 pm, "John David Anderson (_psychic_)" > <[EMAIL PROTECTED]> wrote: >> On Jan 25, 2008, at 6:38 AM, grigri wrote: >> >> >> >>> I'd like to hear some suggestions on cakeifying an existing system. >> >>> Cake's validation is wonderful, but it only allows "yes this is >>> good" >>> and "no it isn't". I've got an application I need to port that has >>> automated warnings built in for some fields. >> >> Have you checked out validation in 1.2? Multiple rules, pre build >> validators, easy custom rules.. I think you can easily do what you >> need in 1.2. >> >> -- John >> >>> Although my system is quite specific (it's a historic family tree, >>> so >>> most of the warnings are like "Warning: this marriage is between two >>> cousins / brother and sister, are you sure?), I could see a generic >>> application, for example for URLs (warning: this URL returns a 404, >>> are you sure you want to add it?) or passwords (this is a crappy >>> password choice, use it at your own risk...). >> >>> My old system gave each warning generated a session-level id and >>> presented an appropriate checkbox in the field 'error' position. The >>> validation routine checked if the checkbox was checked for each >>> registered warning and ignored it if appropriate. If there were no >>> errors, and no unchecked warnings, the form went through. >> >>> My old system was not very flexible, a mish-mash of php includes and >>> whatnot, and I need to cakeify it. >> >>> So, any suggestions on how to introduce this functionality to cake, >>> without rewriting the form helper or model validations? I've got a >>> few >>> ideas but I'd like to hear input. >> >>> (Once I've got a solid "normal" foundation for it, I'd like to >>> extend >>> to js/ajax too, but this is definitely for later) > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---