Last active
December 11, 2015 11:49
-
-
Save Enome/4596942 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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