如何在服务器上提取表单的数据?

时间:2013-05-26 17:08:31

标签: html node.js web-applications express

我有一个表单,想要在提交时将其内容提交给服务器。我在1发现了一个类似的问题,建议使用POST请求,但我不知道该怎么做。 这是我的代码 客户方:

<form method='post' action='http://localhost:8080' >
  <textarea id='chatHistory'></textarea>
  <br/><br/>
  <div class="demo">
   <div class="ui-widget"> 
    <input id="tags" size="50" type="text" />
    <input type="submit" value="Send" style="height:40px;width:120px;font-size:18px;" />
   </div>
  </div>
 </form>     

服务器端:

app.post('/', function(req,res)
{
  // create reusable transport method (opens pool of SMTP connections)
  var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "gmail",
    auth: {
      user: "my_mail_id@gmail.com",
      pass: "password"
    }
});

// setup e-mail data with unicode symbols
var mailOptions = {
 from: "Suggestion Box ✔ <my_mail_id@gmail.com>", // sender address
 to: "receiever@gmail.com", // list of receivers
 subject: "Hello ✔",
 text: req.chatHistory.value
};
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
 if(error){
     console.log(error);
 }else{
     console.log("Message sent: " + response.message);
 }
});
});

邮件正文没有充满客户端的价值。我认为问题在于:req.chatHistory.value

如何在服务器端获取chatHistory值?

1 个答案:

答案 0 :(得分:1)

问题是你从不打电话给req.param("myparam");

尝试:

var chatText = req.param("chatHistory"); 

然后,将其传递给邮件功能:

text: chatText

<强> PS:

<textarea id='chatHistory' name='chatHistory'></textarea>  //add name param

同样:

<input id="tags" size="50" type="text" name='tags' />   //add name param