![](/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.