Is there a good way to validate a HTML form submis...
# http4k
m
Is there a good way to validate a HTML form submission, and render errors for each field in conjunction with that field? If you use
Body.webForm(Validator.Feedback, ...)
, you'll get errors as a
List<Failure>
but I would need it as a map and look up errors for each field.
c
We use data classes to back each form, internally known as FormDTOs. These are build from form submissions by making clever use of Jackson's ability to do type coercion (forms come in as www-url-encoded KV-pairs). We have selected a format for the form field keys (the name attirbutes) as to allow structure. Each FormDTO has a validate method by which it can be validated, we use Konform for that (Akkurate looks also very neat) -- as we like annotation free validation with a declarative syntax.
m
OK, but that seems to deviate from the http4k standard validation quite a bit.
c
yups