user3642365 user3642365 - 26 days ago 5
HTML Question

HTML form not sending data in Express

I have the following form in HTML:

<form method="post" id="registration-form" action="/register">
<div class="form-group">
<label for="UsernameRegistration">Username:</label>
<input type="text" class="form-control" id="UsernameRegistration">
</div>
<div class="form-group">
<label for="PasswordRegistration">Password:</label>
<input type="password" class="form-control" id="PasswordRegistration">
</div>
<div class="form-group">
<label for="ConfirmPasswordRegistration">Confirm Password:</label>
<input type="password" class="form-control" id="ConfirmPasswordRegistration">
</div>
<input type="submit" class="form-control" />
</form>


The
/register
endpoints looks like the following:

router.post('/register', function(req, res, next) {
console.log(req);
});


In req.query and req.body, there is no data. What am I doing wrong?

Answer
<input type="password" class="form-control" id="PasswordRegistration">

Here the attribute name is not specified. It should be like

<input type="password" name="password" class="form-control" id="PasswordRegistration">