Skip to content

Instantly share code, notes, and snippets.

@craftgear
Created February 22, 2011 12:10
Show Gist options
  • Save craftgear/838579 to your computer and use it in GitHub Desktop.
Save craftgear/838579 to your computer and use it in GitHub Desktop.
use express-form as a validator not a middleware
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);
}
})
@dandean
Copy link

dandean commented Feb 23, 2011

The semi-colon on lines 9 and 10 will kill this. They're arguments, so should be separated by commas.

@craftgear
Copy link
Author

thx! I fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment