I would like to know the command to access parameters sent through post method from HTML Forms
I have tried all these but they print undefined or sends back an error ...
EDIT 1: Forgot to mention, I have also added this server.use(express.bodyParser());
EDIT 2:
var express = require('express'),
server = express(),
client = require('mysql').createConnection({ host:'localhost', user:'root', password:'password' });
using dbCRUD for rest services in MySQL
var dbcrud = require('dbcrud').init(client, 'contacts', model);
then I do a
server.use(express.bodyParser());
the post functionality is carried out here..
server.post('/families',function(req,res){
console.log(req.id);
console.log("1: " + req.param.id);
console.log("2: " + req.params.id);
console.log("3: " + req.param("id"));
console.log("4: " + req.params('id'));
console.log("5: " + req.params[0]);
console.log("6: " + req.body.name);
console.log("7: " + req.body.notes);
console.log("8: " + req.body.id);
//console.log("5: " + req.params[0]);
res.send('Hello POST : families');
});
I add the routes here...
dbcrud.addRoutes(server);
In HTML Form i have specified the id and name attributes for the input tag ...
<form method="post" action="http://10.180.218.72:3000/families">
id : <input type="number" id="id" name="id"></input>
name : <input type="text" id="name" name="name"></input>
notes : <input type="text" id="notes" name="notes"></input>
<input type="submit" value = "submit" ></input>
</form>
Try app.use(express.bodyParser()); in your code. bodyParser is a express middleware for parsing body of post request.