I have a form and want to submit its contents to the server on submission.I found a similar question here1 which suggests using a POST request but I am not sure how to do that. Here's my code Client side:
<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>
Server Side:
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);
}
});
});
The body of the mail is not getting filled with the value from the client.I think the problem is here:req.chatHistory.value
How can I get the chatHistory value at the server side?
the problem is that you never call req.param("myparam");
Try:
var chatText = req.param("chatHistory");
Then, pass it to the mail function:
text: chatText
ps:
<textarea id='chatHistory' name='chatHistory'></textarea> //add name param
same with:
<input id="tags" size="50" type="text" name='tags' /> //add name param