Create a form with Jade

Code is put inside a .jade file. These examples were placed inside the index.jade file of an express application.


extends ../layout

block content
    h1= title
    form(name="add-estimation", method="post")
        div.input
            span.label Title
            input(type="text", name="title")
        div.actions
            input(type="submit", value="add")

Add a textarea to the form


extends ../layout

block content
    h1= title
    form(name="add-estimation", method="post")
        div.input
            span.label Title
            input(type="text", name="title")
        div.input
            span.label Description
            textarea(name="description", cols="40", rows="5")
        div.actions
            input(type="submit", value="add")

The input can be fetched in a router.post method. In this example in the index.js files in the routes directory of the express application.


router.post('/', function (req, res) {
    console.log(req.body.title);
    console.log(req.body.description);
    res.send('Post page');
});

Comments

4

I am just getting started with Node.js and Express.js - this was really helpful indeed. I have next to none experience with JavaScript. Still, with tutorials such as this, it makes my life happy! :)

Glad that I could help you!

Greetings,
Jurgen.

 

very helpful thanks

Getting started up with Node.js and Express.js - this was really helpful for me.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.