How to validate and handle a form in Express (NodeJS).

1,378 views
Skip to first unread message

Chris Dew

unread,
Apr 5, 2011, 12:23:55 PM4/5/11
to Express
I know this has been asked before...
http://groups.google.com/group/express-js/browse_thread/thread/d402f31b2d895e67/fa85e36352e124c2
...but perhaps there is a more recent answer?

Cross-posted to http://stackoverflow.com/questions/5555053/how-to-validate-and-handle-a-form-in-express-nodejs

Is there a preferred form handling and validation library for Express?

I'm really looking for a similar level of abstraction as is found in
Django forms - i.e. validation and error reporting through the
template.

If the same validation could be used on the client side, that would be
great.

Has anyone used, or written, anything good?

Thanks,

Chris.

TJ Holowaychuk

unread,
Apr 5, 2011, 1:10:06 PM4/5/11
to expre...@googlegroups.com
IMO most of this should be at the model level, so something
like mongoose would provide validations, you run them and display
the errors if any. on POST you can use express-messages / req.flash('error', msg)
to populate these as one solution

-- 
TJ Holowaychuk
--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

Chris Dew

unread,
Apr 6, 2011, 3:40:12 AM4/6/11
to Express
Generalhenry on Stackoverflow pointed me at https://github.com/caolan/forms,
which looks just the job. I'll give it a run over the next few days
and write a review.

There are reasons why forms should be only loosely coupled to models.
Authorisation is the first which comes to mind: an accounting model
may accept credit notes and invoices in a transaction model, but only
supervisors can create credit notes...

All the best,

Chris.

On Apr 5, 6:10 pm, TJ Holowaychuk <tjholoway...@gmail.com> wrote:
> IMO most of this should be at the model level, so something
> like mongoose would provide validations, you run them and display
> the errors if any. on POST you can use express-messages / req.flash('error', msg)
> to populate these as one solution
>
> --
> TJ Holowaychuk
>
>
>
>
>
>
>
> On Tuesday, April 5, 2011 at 9:23 AM, Chris Dew wrote:
> > I know this has been asked before...
> >http://groups.google.com/group/express-js/browse_thread/thread/d402f3...
> > ...but perhaps there is a more recent answer?
>
> > Cross-posted tohttp://stackoverflow.com/questions/5555053/how-to-validate-and-handle...

TJ Holowaychuk

unread,
Apr 6, 2011, 11:26:25 AM4/6/11
to expre...@googlegroups.com
certainly, and it's nice to abstract regardless, I'm not saying it should always be backed by a model, but usually

-- 
TJ Holowaychuk
Reply all
Reply to author
Forward
0 new messages