Express 无法处理文本区域值

Express cannot process textarea value

我想使用正文解析器在 node.js 中使用 post 方法获取值。但我总是不确定。

下面是我的 node.js 代码。

var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false });

app.get('/form', function (req, res) {
  html += "<form action='/thank'  method='post' name='form1'>";
  html += "<div id='divParent'>";
  html += "<div id='div1' name='formset' class='formset'>";
  html += "<p>Name: <input type= 'text' name='name'></p>";
  html += "<p>Sex: Male <input type='radio' class='gender' name='gender' value='male'>"
  html += " Female <input type='radio' class='gender' name='gender' value='female'></p>"
  html += "<p>Email: <input type='text' name='email'></p>";
  html += "<p>Address:<input type='text' name='address'></p>";
  html += "<p>Mobile number:<input type='text' name='mobilno'></p>";
  html += "<p>Note:</p>"
  html += '<textarea rows="4" cols="50" name="note" id="note" form="form1"></textarea>';
  html += "</div>";
  html += "</div>";
  html += "<input id='input1' type='submit' value='submit'>";
  html += "<INPUT type='reset'  value='reset'>";
  html += "</form>";

  ...
}

app.post('/thank', urlencodedParser, function (req, res){
  var reply='';
  reply += "<br>Array length is : " + req.body.name.length;
  reply += "<br>Your name is : " + req.body.name;
  reply += "<br>Sex is : " + req.body.gender;
  reply += "<br>Your E-mail id is : " + req.body.email; 
  reply += "<br>Your address is : " + req.body.address;
  reply += "<br>Your mobile number is : " + req.body.mobilno;
  reply += "<br>Your note is : "+ req.body.note;
  console.log(req.body)
  res.send(reply);
});

我可以获取输入值,但不能获取文本区域值。 这是我 console.log(req.body)

时得到的

{ name: 'Roy', gender: 'male', email: 'roy@topscore.com', address: 'Bali', mobilno: '0821' }

为什么 body-parser 无法获取 req.body.note?有什么问题?

我认为文本区域实际上并不是表单的一部分,因为您没有 ID 为 "form1" 的表单。从文本区域中删除表单属性或将属性 id 添加到表单中。