0

HTML
This is the form I am using to send the request to my server.

<form action="/compose" method="post">
    <div style="margin-bottom: 1rem; margin-top: 2rem;">
        <label for="exampleInputEmail1" class="form-label">Title</label>
        <input type="text" name="postTitle" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
    </div>
    <div>
        <label class="form-label" for="textAreaExample">Post</label>
        <textarea name="postBody" id="textAreaExample" cols="150" rows="10" class="form-control"></textarea>
    </div>
    
    <button type="submit" name="button" class="btn btn-primary" class="mt-4" 
    style="margin-top: 1rem;">Publish</button>
</form

 I am using nodejs to get catch the post request and logging it

In app.js Here I am logging the request sent to the server

app.post("/compose", function(req, res){
const input = req.body;
console.log(input);
});

problem

Server started on port 3000
{ postTitle: 'dsfds', button: '' }

 But only the postTitle thing is getting logged. Why is that?

1 Answers1

0

So I found a solution to my problem in this post: Here

What I needed to do, is to add a form id="composeForm" to my form and then use that same id inside the textarea(attribute: form="composeForm")

HTML

<form action="/compose" method="post" id="composeForm">
<div style="margin-bottom: 1rem; margin-top: 2rem;">
    <label for="exampleInputEmail1" class="form-label">Title</label>
    <input type="text" name="postTitle" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
<div>
    <label class="form-label" for="textAreaExample">Post</label>
    <textarea name="postBody" id="textAreaExample" cols="150" rows="10" class="form-control" form="composeForm"></textarea>
</div>

<button type="submit" name="button" class="btn btn-primary" class="mt-4" 
style="margin-top: 1rem;">Publish</button>