Trabla: node.js & express.js - get Form POST params
Solving:
Example .jade form
form( action='/login' method='POST' role="form" style="max-width:250px;" )
.form-group
label Login
input(type="text" name="login").form-control
.form-group
label Password
input(type="password" name="password").form-control
input(type="submit" value="Login").btn.btn-primary
p(style='color:red;')= alert
Code in router
router.post('/login',function(req,res){
var login = req.body.login ;
var pass = req.body.password ;
//Dummy user login
if( login == 'user' && pass == 'user' ){
res.render('user_dashboard');
}else{
res.render('login',{alert:'Wrong Login or Password' + login + pass});
}
});
No comments:
Post a Comment