Skip to content

Instantly share code, notes, and snippets.

@Enome
Last active December 11, 2015 11:49
Show Gist options
  • Select an option

  • Save Enome/4596942 to your computer and use it in GitHub Desktop.

Select an option

Save Enome/4596942 to your computer and use it in GitHub Desktop.
var http = require('http');
var express = require('express');
var app = express();
app.get('/my-form', function (req, res, next) {
var form_data = req.flash('form_data');
res.locals.form_data = form_data;
var validation_errors = req.flash('validation_errors');
res.locals.validation_errors = validation_errors;
res.render('my-form');
});
app.post('/my-form/create', function (req, res, next) {
if (validation_fails) {
req.flash('form_data', req.body);
req.flash('validation_errors', [ 'error 1', 'error 2'])
return res.redirect('back');
}
db.save(req.body);
res.redirect('/success');
});
http.createServer(app).listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment