Formidable
Formidable copied to clipboard
How to create a custom error message
So I have followed the docs here: https://formidable.readthedocs.io/en/latest/constraints/#creating-a-simple-constraint and created my own custom error constraint.
When I run the form, I get the error: Non-existent message key "some-error-key" provided
Going over the code I note this message is due to the ErrorFormatter missing the key "some-error-message" and I also note that the constructor of the class can be used to include new custom messages...
My question, however, is, how and where should a custom message be set?
That depends on your application architecture. But generally you'd create the error formatter in a factory and pass it down to your view layer. Where you source your error keys and messages from is up to you. I usually use a config section for that.