使用 body-parser 获取选定的值选项

Using body-parser to get a selected value option

我是网络编程的新手,我正在构建一个应用程序,这让我陷入了一个特定的部分。我正在使用 expressjs 和 body-parser。 我无法像使用 req.body.name.

的文本输入一样从带有 body-parser 的 select 选项中获取 selected 值

HTML:

<form action="/productsAdm" method="POST" enctype="multipart/form-data" class="form-container">
<select name="condition" name="condicaoProduto" id="condition">
    <option value="novo">Novo</option>
    <option value="usado" selected>Usado</option>
</select>
<input type="submit">

后端:

app.post("/productsAdm", upload.array("productPictures"), function(req, res){
  console.log(req.body.condicaoProduto);
  res.redirect("/productsAdm");
})

在表单上使用 enctype 的原因是我也在处理文件传输。

感谢您的帮助:)

您正在定义 selectname 属性两次 这里

<select name="condition" name="condicaoProduto" id="condition">

你应该定义

<select name="condicaoProduto" id="condition">