visionmedia/page.js — pull request #107 by kethinov (2014-06-15 22:34:15+00:00)
Title: Handle forms in a manner similar to body-parser

Here's my take on #106.

This pull request is admittedly kinda rough around the edges and I'm totally open to suggestions for refining it. Probably needs some tweaks before it can be merged and definitely needs unit tests.

But I wanted to get a rough implementation out there to get some discussion going about how something like this could work, since it's a somewhat big expansion on the capabilities of page.js.

The main purpose is to enable workflows like this:

```html

Something

Something else

Apply

Reset to defaults

```

With a page route like:

```js
page('/change', function(req) {

// form data is populated in req.body
// e.g. req.body.something or req.body.somethingElse

if (typeof req.body.change != 'undefined') {
alert('change was pressed');
}
if (typeof req.body.reset != 'undefined') {
alert('reset was pressed');
}
});
```

This allows you to handle forms in a manner similar to how you'd handle forms with server-side Express and [body-parser](https://github.com/expressjs/body-parser).