I am creating a website for each node.js/express. I made a form and it works well. However, when you add the line "enctype = "composite/form data", everything stops working (instead of the values of the input fields, "Avoid" is added to the database).
Handlebars:
<form action="/target/" method="POST" enctype="multipart/form-data">
<label for="name">Имя:</label>
<input name="name"><br><br>
<label for="age">Возраст:</label>
<input name="age"><br><br>
<label for="comm">Комментарий:</label>
<input name="salary"><br><br>
<label for="img">Картинка:</label>
<input type="file" name="f">
<input type="submit">
</form>
Node:
mongoClient.connect(async function(error, mongo) {
if (!error) {
let db = mongo.db('NODE_db');
let coll = db.collection('users');
app.post('/target/', urlencodedParser, async function(req, res) {
//Validation
if (req.body.name == '' || req.body.age == '' || req.body.comm == ''){
res.status(400).json({mess: "fill fields"})
}
else {
await coll.insertOne(req.body);
res.redirect('/')
}
});
} else {
console.error(error);
}
});