0

I've got the following small express.js app and the corresponding .jade file. Server is running without errors but when I submit the button, nothing happens. I would expect that the app.post(...) is called, but it is not.

Could someone point me to the mistake?

var express = require('express');
var http = require('http');
var bodyParser = require ('body-parser');

var app = express();


var port = process.env.PORT || 9250;
var host = process.env.HOST || "127.0.0.1";

var server = http.createServer(app).listen(
		port,
		host,
		function() {
			console.log("Server listening to %s:%d within %s environment",
					host, port, app.get('env'));
		});


app.set('views', __dirname + '/views');
app.engine('.html', require('jade').__express);

app.use( bodyParser.json() ); 
app.use(bodyParser.urlencoded({ extended: true }));


app.get('/', function(req, res) {
	res.sendFile(app.get('views') + '/index.html')
});

app.get('/test', function(req, res) {

	res.render('home.jade');
});

app.post('/claim', function(req, res) {
	console.log('called');
	res.redirect('/');
});
doctype html
html(lang="en")
  head
    title Hello

  body
    h1 Welcome
    p Description

    form(action="/claim", method="post")
    label Input something
    br
    input(type="text", name="address", size=50)
    br
    input(type="submit", value="Submit")

1 Answer 1

3

Your problem is indentation : Jade doesn't understand your input is included in form.

Try this, it works for me :

doctype html
html(lang="en")
  head
    title Hello

body
  h1 Welcome
  p Description

  form(action="/claim", method="post")
    label Input something
    br
    input(type="text", name="address", size=50)
    br
    input(type="submit", value="Submit")
1
  • Great, the indentations were the problem. Thanks! It works fine now!
    – nullpointr
    Sep 20, 2015 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.