{"_id":"iform","_rev":"12-f8f68c9edf9e18f988a490a6deaf1630","name":"iform","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"iform","version":"0.0.1","author":{"name":"Lin Gui","email":"guileen@gmail.com"},"_id":"iform@0.0.1","maintainers":[{"name":"guileen","email":"guileen@gmail.com"}],"dist":{"shasum":"b803ed0db0775c16692376ec576fd2595be85b9b","tarball":"https://registry.npmjs.org/iform/-/iform-0.0.1.tgz","integrity":"sha512-HnDzhm+LJSyXuii1YOIhYT+GmGU08blCcHaJVepVO4vEMq7S8WkDT+mNvmYVohrmr5ocRukXZulXyS97WCVWfw==","signatures":[{"sig":"MEUCIFwJreDa1Nb3bo2qpFs0dg3T+lnfNIbqTpLpE031wRj1AiEAiXnu29TDLJjABEWsRB5CkBS1lwxx6JBKPR+S6si5tz4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"iform.js","engines":{"node":"*"},"_npmUser":{"name":"guileen","email":"guileen@gmail.com"},"repository":{"url":""},"_npmVersion":"1.0.104","description":"generate html5 style form and do validation","directories":{},"_nodeVersion":"v0.6.1-pre","dependencies":{"validator":">= 0.1.0"},"_defaultsLoaded":true,"devDependencies":{"jade":">= 0.1.0","express":">= 2.0.0"},"_engineSupported":true},"0.0.2":{"name":"iform","version":"0.0.2","author":{"name":"Gui Lin","email":"guileen@gmail.com"},"_id":"iform@0.0.2","maintainers":[{"name":"guileen","email":"guileen@gmail.com"}],"bugs":{"url":"https://github.com/kissjs/connect-iform/issues"},"dist":{"shasum":"9bad6d8d7b3f1ea45b121877e5e9535a83067406","tarball":"https://registry.npmjs.org/iform/-/iform-0.0.2.tgz","integrity":"sha512-7zX0w/ho6PEd3WxZOORktIkw1EA7p8jYb5edsS34zQDmrDmDu2nGCBiF+oX+t/t2JK/AjkgCswfijlTBJTU1ng==","signatures":[{"sig":"MEUCIQDEzQxGYXyg8GyjT2EFHgqaFJztNy2r2FRTLMOTpfsiKwIgPoWIs3KFkHbjRr4/m4Lh/sp2Lo0Cmwwx20DoxwVNCKY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"iform.js","_from":".","readme":"node-iform\n====\n\nnode-iform is a connect middleware help you validate and convert form data.\n\n\n**NOTE** You need to view [node-validator](https://github.com/chriso/node-validator)\nfor more information.\n\n**NOTE** If you find a bug, or want some feature, send a **pull request**.\n\nInstall\n----\n\n    npm install iform\n\nExample\n----\n\n```javascript\n    var iform = require('iform');\n\n    var userForm = iform({\n            username: {\n                required : true,\n                len : [4, 15]\n            },\n            password: {\n                required : true,\n                len : [6, 20]\n            },\n\n            email : {\n                type : 'email'\n            },\n\n            birth : {\n                type : Date,\n                isAfter: new Date('01/01/1900'),\n                isBefore : null // means now\n            },\n\n            avatar : {\n                defaultValue : function(req) {\n                    return '/avatar/' + req.body.username + '.png';\n                }\n            },\n\n            age : 'int',\n\n            blog : 'url'\n    });\n\n    app.post('/signup', userForm(), function(req, res, next) {\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.insert(req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Sign up successfully'});\n            });\n    });\n\n    app.post('/profile', userForm('birth', 'age', 'blog'), function(req, res, next){\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.update({username : req.session.user.username}, req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Update profile successfully'});\n            });\n    });\n```\n\n### define rules\n\nAt first you need define some rules for validation\n\nAs you can see in the example, define a form like this : `var form = iform(rules);`\n\n`rules` is like `{fieldName : fieldRules, ...}`\n\n`fieldRules` is like `{ruleName : ruleParameter, ...}`\n\n```javascript\n        // field name | rule name | rule parameters\n           username  :{ len       : [4, 15] }\n```\n\nThe rule names can find at [node-validator](https://github.com/chriso/node-validator) project page.\n\nAll the methods of Validator and Filter of node-validator can be use as a rule name.\nThe rule parameters is the arguments for that method.\n\nThe `len` is defined by [node-validator](https://github.com/chriso/node-validator) like this\n\n```javascript\n    Validator.prototype.len = function(min, max) { ... }\n```\n\nIt takes two parameters. so we use an array as the parameters.\n\nThe `type` is a special rule ,e.g.\n\n```javascript\n    email : {\n        type : 'email'\n    }\n```\n\nit is equals to\n\n```javascript\n    email : {\n        'isEmail' : []\n    }\n```\n\nyou can also use `int`, `date` etc, cause the Validator defined `isInt` and `isDate`\n\nall the method of Valiator starts with `is` and take no arguments can be use as a type.\n\nif you only have a type rule you can use `fieldName : type` define it.\n\nYou can also use `Date` `Number` instead of `'date'`, `'number'`\n\n### use the middleware\n\n`userForm` you just defined is a function which returns a middleware, use like this\n\n```javascript\n    app.post('/signup', userForm(), function(req, res, next) {\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.insert(req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Sign up successfully'});\n            });\n    });\n```\n\nthe middleware will check the `req.body` by your rules, all the validation errors \ngo to `req.iform.errors`, and the filtered and converted data go to `req.iform.data`.\n\nSince the data has been cleaned, you can use it immediately.\n\nIf there is another page also use the smae rules but only part of fields,\nyou can reuse it like this.\n\n```javascript\n    app.post('/profile', userForm('birth', 'age', 'blog'), function(req, res, next){\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.update({username : req.session.user.username}, req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Update profile successfully'});\n            });\n    });\n```\n","engines":{"node":"*"},"_npmUser":{"name":"guileen","email":"guileen@gmail.com"},"repository":{"url":"git://github.com/kissjs/connect-iform.git","type":"git"},"_npmVersion":"1.3.5","description":"Form data validation middleware","dependencies":{"validator":"*"},"readmeFilename":"Readme.md","devDependencies":{},"directories":{}}},"time":{"created":"2011-11-19T18:06:27.231Z","modified":"2025-02-27T14:09:19.770Z","0.0.1":"2011-11-19T18:06:31.203Z","0.0.2":"2013-08-16T10:20:42.120Z"},"author":{"name":"Gui Lin","email":"guileen@gmail.com"},"repository":{"url":"git://github.com/kissjs/connect-iform.git","type":"git"},"description":"Form data validation middleware","bugs":{"url":"https://github.com/kissjs/connect-iform/issues"},"maintainers":[{"name":"guileen","email":"guileen@gmail.com"}],"readme":"node-iform\n====\n\nnode-iform is a connect middleware help you validate and convert form data.\n\n\n*NOTE* You need to view [node-validator](https://github.com/chriso/node-validator)\nfor more information, if you want to use this node-iform.\n\n*NOTE* If you find a bug, or want some feature, send a pull request.\n\nExample\n----\n\n```javascript\n    var iform = require('iform');\n\n    var userForm = iform({\n            username: {\n                required : true,\n                len : [4, 15]\n            },\n            password: {\n                required : true,\n                len : [6, 20]\n            },\n\n            email : {\n                type : 'email'\n            },\n\n            birth : {\n                type : Date,\n                isAfter: new Date('01/01/1900'),\n                isBefore : null // means now\n            },\n\n            avatar : {\n                defaultValue : function(req) {\n                    return '/avatar/' + req.body.username + '.png';\n                }\n            },\n\n            age : 'int',\n\n            blog : 'url'\n    });\n\n    app.post('/signup', userForm(), function(req, res, next) {\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.insert(req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Sign up successfully'});\n            });\n    });\n\n    app.post('/profile', userForm('birth', 'age', 'blog'), function(req, res, next){\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.update({username : req.session.user.username}, req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Update profile successfully'});\n            });\n    });\n```\n\n### define rules\n\nAt first you need define some rules for validation\n\nAs you see in the example, define a form like this : `var form = iform(rules);`\n\n`rules` is like `{fieldName : fieldRules, ...}`\n\n`fieldRules` is like `{ruleName : ruleParameter, ...}`\n\n```javascript\n        // field name | rule name | rule parameters\n           username  :{ len       : [4, 15] }\n```\n\nThe rule names can find at [node-validator](https://github.com/chriso/node-validator) project page.\n\nAll the methods of Validator and Filter of node-validator can be use as a rule name.\nThe rule parameters is the arguments for that method.\n\nThe `len` is defined by [node-validator](https://github.com/chriso/node-validator) like this\n\n```javascript\n    Validator.prototype.len = function(min, max) { ... }\n```\n\nIt takes two parameters. so we use a array as the parameters.\n\nThe `type` is a special rule ,e.g.\n\n```javascript\n    email : {\n        type : 'email'\n    }\n```\n\nit is equals to\n\n```javascript\n    email : {\n        'isEmail' : []\n    }\n```\n\nyou can also use `int`, `date` etc, cause the Validator defined `isInt` and `isDate`\n\nall the method of Valiator starts with `is` and take no arguments can be use as a type.\n\nif you only have a type rule you can use `fieldName : type` define it.\n\nYou can also use `Date` `Number` instead of `'date'`, `'number'`\n\n### use the middleware\n\n`userForm` you just defined is a function which returns a middleware, use like this\n\n```javascript\n    app.post('/signup', userForm(), function(req, res, next) {\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.insert(req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Sign up successfully'});\n            });\n    });\n```\n\nthe middleware will check the `req.body` by your rules, all the validation errors \ngo to `req.iform.errors`, and the filtered and converted data go to `req.iform.data`.\n\nSince the data has been cleaned, you can use it immediately.\n\nIf there is another page also use the smae rules but only part of fields,\nyou can reuse it like this.\n\n```javascript\n    app.post('/profile', userForm('birth', 'age', 'blog'), function(req, res, next){\n            if(req.iform.errors) {\n                return res.json(req.iform.errors);\n            }\n            db.users.update({username : req.session.user.username}, req.iform.data, function(err, data) {\n                res.json({success : true, message: 'Update profile successfully'});\n            });\n    });\n```\n","users":{}}