![](/img/trans.png)
[英]How to not add the user to the database if the date is later than today's date?
[英]how to add user's information in mongoose database?
我有.jade格式的注册表
form(method='post', action='/users/register', enctype='multipart/form-data')
.form-group
label Name
input.form-control(name='name', type='text', placeholder='Enter Name' required)
.form-group
label Email
input.form-control(name='email', type='email', placeholder='Enter Email' required)
.form-group
label Username
input.form-control(name='username', type='text', placeholder='Usernamee' required)
.form-group
label Password
input.form-control(name='password', type='password', placeholder='Enter Password' required)
.form-group
label Password
input.form-control(name='password2', type='password', placeholder='Confirm Password' required)
.form-group
label Profile Image
input.form-control(name='profileimage', type='file')
input.btn.btn-default(name='submit', type='submit', values='Register')
这就是我创建新用户并将其添加到数据库中的方法,但是数据并未添加到数据库中。 问题是它没有从表单字段中获取值:名称,电子邮件用户名,密码都为NULL我不知道为什么,因为它应该采用所有值
router.post('/register', function(req, res, next) {
var newUser = new User({
name: req.body.name,
email: req.body.email,
username: req.body.username,
password: req.body.password,
profileImage: profileImageName
});
}
您需要一个主体解析中间件来解析传入的请求主体。
从v4.16.0开始,Express具有内置的中间件功能 (基于body-parser
模块)来解析经过urlencoded的主体。 但是,此内置解析器无法处理多部分主体。
由于您尝试处理multipart/form-data
,因此可能需要像multer这样的中间件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.