Created
June 24, 2015 16:29
-
-
Save quis/a94126ce35a7b1b24ac9 to your computer and use it in GitHub Desktop.
Branching questions in express prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bodyParser = require("body-parser"); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
var pages = [ | |
{ | |
next: { | |
yes: 1, | |
no: 4 | |
} | |
}, | |
{ | |
next: { | |
yes: 2, | |
no: 4 | |
} | |
}, | |
{ | |
next: { | |
yes: 3, | |
no: 4 | |
} | |
} | |
]; | |
app.get('/page/:number', function (req, res) { | |
res.send("Hello page " + req.params.number + | |
"<form action='/page/" + req.params.number + "' method='post'>" + | |
"<input type='radio' name='value' value='yes'/> Yes" + | |
"<input type='radio' name='value' value='no'/> No" + | |
"<input type='submit' />" + | |
"</form>"); | |
}); | |
app.post('/page/:number', function(req, res) { | |
var nextPage = pages[req.params.number].next[req.body.value]; | |
res.redirect('/page/' + nextPage); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment