MVC with Dancer2 and DBIC: Form Validation
A few days ago I pushed to GitHub a sample web application written in the MVC style with Dancer2 and DBIx::Class. In this very first post about it, I'd like to highlight
how a route block that processes and validates form data can be made short and neat with the help of HTML::FormHandler.
Consider this HTML form from the application which creates a new user:
The Dancer2 route that handles it looks as simple as this:
Once the form is submitted, HTML::FormHandler processes the parameters from Dancer2. If it is not valid, HFH produces error messages and the form is rendered again with the original input.
Otherwise, a new account gets created automatically and the user finds himself on the welcome page already logged in.
That's it for now. I hope this post helps you save some typing in your next Dancer2 project.