gpt4 book ai didi

javascript - NodeJS : Input values not reset to their given values

转载 作者:太空宇宙 更新时间:2023-11-04 00:47:21 24 4
gpt4 key购买 nike

这里有我正在处理的用于表单验证的 NodeJS 代码。我无法让它重置用户输入的值。

验证没有做任何事情,我只是想用用户提供的值重置输入表单的值。请有人帮助我。

代码如下:

注册路线:

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;

注册索引.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>

最佳答案

好吧,您输入的名称/id 是 form-first-name,但因为您使用了 firstname 而不是 form-first-name;用户提供的值不会被重置。将其替换为:

<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 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}}">

这会起作用。

干杯。

关于javascript - NodeJS : Input values not reset to their given values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34133622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com