Monday, 15 May 2017

Unable to access form elements from NodeJS

So my form is:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
        <title>Title</title>
  </head>
  <body>
     <form action="/upload" method="post"        enctype="multipart/form-data">
        <input type="text" name="name" placeholder="name"> <br />
        <input type="submit" value="Upload">
     </form>
  </body>
</html>

And in node:

app.post("/upload", function(req, res){

var name = req.body.name;
// Also tried: req.query.name;

console.log(name);
} );

I'm getting undefined. Why can't I get the value of the text?

Please help.



via Somename

No comments:

Post a Comment