0

I am attempting to submit data in my NodeJS app. I've been using Postman with a single name entry in json and my app is able to detect the post body data. Screen shot below:

enter image description here

My problem is I can't get my html markup to submit data successfully. I provide the data to the form but the nodejs function receiving the submission shows that the request data is empty.

The following is the form markup:

<form id="join_queue" action="/join_queue" method="post" enctype="application/json">
    <label for="">Please provide a name: </label>
    <input type="text" name="name" id="name">
    <input type="submit" value="Join">
</form>

And here is my Nodejs function responding to the form submission:

app.post('/join_queue', (req, res) => {
    console.debug('Post body: ', req.body)
    console.debug('Post param: ', req.params)
    res.render('join.ejs')
})

All I get is Post body: {} and the same for params.

What am I doing wrong or missing here? How can I get my html form to behave the same as the postman form?

halfer
  • 19,824
  • 17
  • 99
  • 186
sisko
  • 9,604
  • 20
  • 67
  • 139

1 Answers1

0

I needed to include the body-parser middleware in order to get form submission data as indicated here.

I.E:

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }));
sisko
  • 9,604
  • 20
  • 67
  • 139