lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 16 June 2015 at 23:51, Aapo Talvensaari <aapo.talvensaari@gmail.com> wrote:
> I'm quite happy with lua-resty-validation but a few things needs to be resolved still. E.g. those that I mentioned in my previous post in this thread.

Those problems were:

1. How should I implement "optional" filters (and what to do with them, skip or continue with next, or should this be parameterized somehow)
2. How should I implement "stop" filters (aka those that skip rest of the chain)
3. How should I implement "default" values (do I need to have this by filters or by filter chain or both)
4. Should I split validation (e.g. true/false checks) and filters (those that modify values) – righth now my implementation supports validators, filters and validating filters (but this might look too much magic).
5. How should I handle absent values (missing values and nils don't neccessarely mean that something is wrong with input, see below).


And also a few other probems:

6. Allow validation / filtering on some other value only happen if some other GET/POST values is something.
7. Check that two fields contain same value
8. If one check box is checked the value of other field should be say between 1 and 10 and if not checked it can be between 1 and 100, for example.
9. Support multivalued fields (e.g. ?foo=1&foo=apple&foo=foo)

I can do this just fine right now:
local ok, err = validation.tonumber().between(1, 100).outside(40, 50)(cgi.get['foo'])

And of course this can be reused:
local is_some_important_number = validation.tonumber().between(1, 100).outside(40, 50)
local ok, err = is_some_important_number(cgi.get['foo'])

But it is pretty hard to combine all the functionality (e.g. those mentioned above) neatly in these kind of oneliners. But I'm quite close, it just needs some rethinking (maybe I need to split some functionality or just use a few if clauses on more difficult input data).