Estoy creando un sitio web para cada node.js/express. Hice un formulario y funciona bien. Sin embargo, cuando agrega la línea "enctype = "composite/form data", todo deja de funcionar (en lugar de los valores de los campos de entrada, se agrega "Evitar" a la base de datos).
Bigote daliniano:
<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>Nodo:
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); } });