1. Vonage Learn
  2. Courses
  3. Onehack
  4. Node
  5. Data From Forms

Getting Data from Forms

Learn how to use Node.js, Express.js and Nunjucks to create dynamic web applications

new.html

<!doctype html>
<html>
    <head>
        <title>OneHack Academy</title>
    </head>
    <body>
        <form action="/new" method="POST">
            <input type="text" placeholder="Film Name" name="name">
            <input type="text" placeholder="IMDB ID" name="id">
            <button>Submit</button>
        </form>
    </body>
</html>

GET /new Route Handler

app.get('/new', function(req, res) {
    res.render('new.html');
});

Body Parser Set Up

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

POST /new Route Handler

app.post('/new', function(req, res) {
    films.push(req.body);
    res.redirect('/');
});

Need help? Have questions? Join the Vonage Developer Community Slack and use the channel #onehack.