Form data sent to Node via Post is undefined

Posted by user185812 on Stack Overflow See other posts from Stack Overflow or by user185812
Published on 2013-06-30T02:52:32Z Indexed on 2013/06/30 4:21 UTC
Read the original article Hit count: 375

Filed under:
|
|

I know this has been asked countless times on here, however I tried all the solutions and am still having the issue. Most people say to set the content-type (which I did) and to name the inputs that I wish to Post to node. I have done both of these things, yet still get "undefined" when trying to send data from an HTML form to node.

JADE Templating HTML Code (Sorry I can't seem to get the indenting to show up here, however I think I should leave the code intact when posting here instead of converting it to normal HTML so that if the error is in here, you are still able to help)

Form(action="/registration", method="post",
enctype="application/x-www-form-urlencoded")   
div(class="control-group-Username")
    label(class="control-group", for="username") Username:
        div.controls
            input#Username(id="Username", type="text", placeholder="Username Here", maxlength="23", name="username")

//Other divs and stuff here

button.btn#submit_button(type="submit") Submit

app.js code

/**  * Module dependencies.  */

express = require('express')   , routes = require('./routes')   ,
user = require('./routes/user')   , http = require('http')   , path = require('path');

app = express();

// all environments app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views'); app.set('view engine','jade');
app.use(express.favicon()); app.use(express.logger('dev'));
app.use(express.bodyParser()); app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session()); app.use(app.router);
app.use(require('less-middleware')({ src: __dirname + '/public' }));
app.use(express.static(path.join(__dirname, 'public')));

// development only if ('development' == app.get('env')) {  
app.use(express.errorHandler()); }

app.use(express.static(__dirname + '/public'));
app.get('/', routes.index);
app.get('/users', user.list);
app.get('/register', routes.register);

http.createServer(app).listen(app.get('port'), function(){
    console.log('Express server listening on port ' + app.get('port'));
});

require('./Register.js');

register.js code

app.post('/registration', function(req, res) {
    var Email=req.body.username     
    console.log(username);
});

© Stack Overflow or respective owner

Related posts about html

Related posts about node.js