form handling
I just added another item to my tasklist for 1.0.0. It’s about using model classes and objects to populate forms.
Generally this works quite well, but every now and then there is this ugly exception that makes it very hard to use.
Perhaps the most famous example of those exceptions is the date of birth field in the create/edit account forms. There have been several attempts at fixing this, usually by changing the way dates are converted and formatted. However, those changes do not take into account the real issue: the date format in the model class and the format in the form do not match.
Well, you might say this is all taken care of by converting the input in the populate() method of ZMAccount and by using $locale->shortDate() in the template.
Unfortunately, this leaves out the most critical case: an invalid date. If that happens, the invalid date gets converted into the internal format and then back to the presentation format. Usually, the result is not very nice to look at. Another issue is that the validation will look at the actual input, rather than the converted value in the model.
So, it looks like there have to be some more classes to decouple that.
One benefit could be that the validation could change to work entirely on those objects rather than the raw input. This could also make it easier to push feedback out of the validation process.
On the other hand some validation might depend on the custom processing that is currently done in the populate method of some model classes, even though I think that this is actually bad design rather than a feature.
I have a few ideas I’ll be playing with and some might actually work without template changes which would be a good thing.
