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:

signup-form.png

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.

signup-form-invalid.png

Otherwise, a new account gets created automatically and the user finds himself on the welcome page already logged in.

welcome-user.png

That's it for now. I hope this post helps you save some typing in your next Dancer2 project.

2 Comments

Please could you edit your post so that most of it lies "below the fold"? There are two sections in the edit window that let you write the preamble and then the rest. thanks!

I think this is an excellent post. Dancer is a great framework but we need more indepth examples like this (that utilise things like MVC, DBIC and HFH) to help people get their heads around how they can use it in real life situations. I know there are Catalyst examples but it's nice to see something up to date done in Dancer.

Leave a comment

About Sherwin Daganato

user-pic A forever student of programming languages. Loves Perl but doesn't mind using PHP or RoR for web development.