I'm trying to get the values from some fields of an index HTML but the post method send me back empty values. It returns this { }, with no values inside of email,nick,name and pass.
this is my server.js code:
var mongoose = require('mongoose');
var express = require('express');
var app=express();
var bodyParser = require('body-parser');
mongoose.connect("mongodb://localhost/myDB");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
app.post("/",function(solicitud,respuesta){
console.log(solicitud.body);
});
app.listen(8080);
and here is the HTML form code:
<div class="col-md-5 center-block no float top-pace text-left">
<form method="post" action="/" style="margin-top:1.5em;">
<!--EMAIL -->
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="[email protected]" required autofocus/>
</div>
<!--NICK -->
<div class="form-group">
<input type="text" class="form-control" id="nick" placeholder="Enter your nickname">
</div>
<!--NAME -->
<div class= "form-group">
<input type="text" class="form-control" id="nombre" placeholder="Enter your name">
</div>
<!--PASS -->
<div class="form-group">
<input type="password" class="form-control" id="pass" placeholder="***************">
</div>
<!--BOTON -->
<div class="form-group">
<button type="submit" class="btn btn-default" onclick= "alerta()">Sign Up </button>
</div>
</form>
</div>
May the url of the app.post is bad? the form is located in the index.html
Thank you for your help
The input elements must have name attribute.