Created
February 22, 2011 12:10
-
-
Save craftgear/838579 to your computer and use it in GitHub Desktop.
use express-form as a validator not a middleware
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 form = require('express-form'); | |
validate = form.validate; | |
filter = form.filter; | |
/* setup express server here */ | |
app.get('/', function(req,res){ | |
form( | |
validate('foo').required(), | |
validate('bar').required('a placeholder text for bar', 'a customize error message here') | |
)(req, res) | |
if(!req.form.isValid){ | |
//error handling | |
console.log(req.form.errors); | |
} | |
else{ | |
//submit data handling | |
console.log(req.form.foo); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The semi-colon on lines 9 and 10 will kill this. They're arguments, so should be separated by commas.