prcbass prcbass - 1 year ago 151
HTML Question

req.body empty for textarea in http form (Using Express)

I have the following form to have the user upload a file and submit text:

form(action='/createpost' enctype="multipart/form-data" method='post' id="imgForm")
input(type='file' name='imgPath' size = "60")
textarea(name="postText" form="imgForm") Enter your post text here...
input(type='submit' value="Submit")

When I run this:'/createpost', function(req,res){
console.log("POST FORM BODY", req.body.postText);

I get
in the console. How do I get the value of the input inside textarea?

Answer Source

Try removing the enctype="multipart/form-data" part in the form and see if it works. I think servers interpret data sent in multipart differently.

I don't know if I understand what enctype="multipart/form-data" does, but I'd use it when uploading a file from a form and the node module multiparty

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download