1
Good morning guys, I’m making a form, using Node and the EJS view engine, however I’m having trouble getting data from the forms in the controller. The return of req.body is always Undefined.
app.js with body-parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
Form . EJS
<form method='post' action='/save' enctype='multipart/form-data'>
<label> Paciente </label> <br />
<input type='text' name='patient' value='oi' /> <br />
<label> Imagem: </label> <br />
<input type='file' id='image' name='image' /> <br />
<label>Descrição: </label> <br />
<textarea id='description' name='description' rows=3></textarea> <br />
<button type='submit'> Enviar </button>
</form>
Controller, with post method:
router.post('/save', (req, res) => {
console.log(req.body.patient);
console.log(req.body.description);
});