NodeJS:input值不会重置为给定的值

在这里,我有我正在处理的表单validation的NodeJS代码。 我不能得到它重置用户的价值。

validation不会做任何事情,我只是想用用户提供的值重置input表单的值。 有人请帮助我。

代码如下:

注册路线:

var express = require('express'); var router = express.Router(); router.get('/', function(req, res, next) { var vm = { title: 'Join us now, Brovis' }; res.render('signup', vm); }); router.post('/', function(req, res, next) { var flagChecker= true; if (flagChecker) { var vm = { title: 'Create an account', input: req.body, error: 'Something went wrong, Brovis' }; delete vm.input.password; return res.render('signup', vm); } res.redirect('/'); }); module.exports = router; 

注册的index.hbs:

 <link rel="stylesheet" href="css/silog.css"> <div class="jumbotron"> <div class="container"> <div class = "row"> <div class = "col-md-6 theForm"> <div class="form-box"> <div class="form-top"> <h2>Sign up now</h2> <p>Join the community now:</p> </div> </div> <div class="form-bottom"> <form role="form" action="" method="post" class="registration-form"> <div class="form-group"> <label class="sr-only" for="firstname">First name</label> <input type="text" name="form-first-name" placeholder="First name" class="form-first-name form-control" id="form-first-name" required value = "{{input.firstname}}"> </div> <div class="form-group"> <label class="sr-only" for="password">Last name</label> <input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="form-last-name" required value = {{input.password}}> </div> <button type="submit" class="btn">Sign me up!</button> </form> </div> <span style = "color:red; font-weight: 600">{{error}}</span> </div> </div> </div> 

那么,你的input名称/编号是form-first-name ,但是因为你已经使用firstname而不是form-first-name ; 用户提供的值没有被重置。 将其replace为:

 <input type="text" name="form-first-name" placeholder="First name" class="form-first-name form-control" id="form-first-name" required value = "{{input.form-first-name}}"> 

另外,您错过了第二个input字段中的引号。 它应该是:

 <input type="text" name="form-last-name" placeholder="Last name..." class="form-last-name form-control" id="form-last-name" required value = "{{input.form-last-name}}"> 

这将工作。

干杯。