Best way to display form validation errors in a Node.js application using Express?

Our registration formats and logins require server-side validation logic. I would like to find the best way to display messages for each input block on the client.

Application Stream:

  • Send form to client side
  • Node check
  • Redirect to the view that displays the form in step 1.

I tend to req.flash()display form input messages, but maybe there is a more OOP approach for this?

+3
source share
2 answers

, . , , , , .

:

include ../mixins/form-helpers

mixin errors()

form(action=url('messages_create'), method='post')

  mixin csrf()

  fieldset

    legend contact

    mixin field('text', 'subject', 'Subject')
    mixin field('textarea', 'message', 'Message')

  .form-actions
    mixin submit('Send')

, .

var errors = { subject: ['is required'], message: ['is required'] };

mixin , mixin , .

+1
0

All Articles