{"id":19118497,"url":"https://github.com/loulafripouille/express-form-handler","last_synced_at":"2026-05-03T11:33:46.733Z","repository":{"id":97179721,"uuid":"56396708","full_name":"loulafripouille/express-form-handler","owner":"loulafripouille","description":"[DEPRECATED] Form handler for express node.js framework","archived":false,"fork":false,"pushed_at":"2017-05-17T10:41:41.000Z","size":164,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T04:58:22.440Z","etag":null,"topics":["express","express-js","expressjs","form-handler","form-validation","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loulafripouille.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-16T17:30:23.000Z","updated_at":"2018-03-02T16:52:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"ddd4cd17-7254-45b1-8c94-168a2318d033","html_url":"https://github.com/loulafripouille/express-form-handler","commit_stats":null,"previous_names":["laudeon/express-form-handler"],"tags_count":52,"template":false,"template_full_name":null,"purl":"pkg:github/loulafripouille/express-form-handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loulafripouille%2Fexpress-form-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loulafripouille%2Fexpress-form-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loulafripouille%2Fexpress-form-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loulafripouille%2Fexpress-form-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loulafripouille","download_url":"https://codeload.github.com/loulafripouille/express-form-handler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loulafripouille%2Fexpress-form-handler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32567415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","express-js","expressjs","form-handler","form-validation","nodejs"],"created_at":"2024-11-09T05:06:38.422Z","updated_at":"2026-05-03T11:33:46.714Z","avatar_url":"https://github.com/loulafripouille.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-form-handler [v2 - beta]\n\nA form handler for the Node.js framework: Express.js\n\n[![Build Status](https://travis-ci.org/laudeon/express-form-handler.svg?branch=master)](https://travis-ci.org/laudeon/express-form-handler) [![npm version](https://badge.fury.io/js/express-form-handler.svg)](https://badge.fury.io/js/express-form-handler)\n[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n- [Why?](#why)\n- [Get Started](#get-started)\n  - [Install](#install-via-npm)\n  - [Create a form](#create-a-form-file)\n  - [The middleware](#use-the-route-middleware)\n  - [Extend a form](#extend-a-form)\n- [Go further](#go-further)\n  - [Configuration](#configuration)\n  - [Model Strategy](#model-strategy)\n  - [Rules \u0026 Formats](#rules-and-formats)\n- [Contribute](#contribute)\n- [Changelog](#changelog)\n\n# Why?\n\n**Make the form hanlding easier by avoiding repetitive tasks such as fields validation or find the one element to update according to the id route parameter.**\n\n**Define a form** (fields, field format \u0026 validation rules, ...), process the form validation with a route middleware then use the `req.form` object into the next route middleware to check the form validity or get form values.\n\n**Extend a form** with other forms.\n\n**Create your own formats and rules.**\n\n**Attach a model** to a form through a **model strategy** in order to automate data binding to it. When a `:id` parameter is present in the `req.params` object, form-handler will try to find the corresponding document into the database before update it.\n\nCreate a custom model strategy corresponding to your ODM / ORM.\n\nChose the way you want to process the validation: by the defined form's fields format and rules or by the model strategy `validate()` method.\n\n# Get Started\n\n## Install via npm\n\nRun `npm install --save express-form-handler@2.0.0-beta.11`\n\n## Create a form file\n\n```js\nconst formHandler = require('express-form-handler')\nconst MongooseStrategy = require('express-form-handler-mongoose')\nconst User = require('./models/user')\n \nlet form = formHandler.create([\n  {\n    name: 'username',\n    label: 'Username',\n    format: formHandler.format.string(),\n    rules: [\n      formHandler.rule.required(), \n      formHandler.rule.minlength(4)\n    ]\n  }, \n  {\n    name: 'password',\n    label: 'Password',\n    format: formHandler.format.string(),\n    rules: [\n      formHandler.rule.required(), \n      formHandler.rule.minlength(6)\n    ]\n  },\n  {\n    name: 'passwordConfirm',\n    label: 'Confirm password',\n    format: formHandler.format.string(),\n    rules: [\n      formHandler.rule.required(),\n      formHandler.rule.equalsto('password')\n    ]\n  }\n])\n\nform.config({\n  modelStrategy: new MongooseStrategy(User),\n  validationByModel: false\n})\n\nmodule.exports = exports = form\n\n```\n\n### formats supported (with node-validator help!)\n\n- **alpha** - check if the string contains only letters (a-zA-Z).\n- **alphanumeric** - check if the string contains only letters and numbers.\n- **date** - check if the string is a date.\n- **email** - check if the string is an email.\n- **float** - check if the string is a float.\n- **int** - check if the string is an integer.\n- **numeric** - check if the string contains only numbers.\n- **url** - check if the string is an URL.\n\n### Form constraints supported\n\n- **equalsto** - check if the field value match with the given field's label value.\n- **required** - check if the field value exist and is not empty|false|null.\n- **custom** - a custom function that must return a boolean and accept the field value as first argument\n- **minlength**\n- **maxlength**\n\n## Use the route middleware\n\n*Forms must be submitted by POST, PUT or PATCH method.*\n\n```js\nconst userForm = require('./user-form');\n\n//...\n\napp.post('/registration', userForm.process, function(req, res, next) {\n    if(!req.form.isValid) {\n        return next({ error: { status:400 } });\n    }\n    \n    //else...\n    console.log(req.form.username);\n    console.log(req.form.password);\n    console.log(req.form.model);\n});\n```\n\n## Extend a form\n\n```js\nconst formHandler = require('express-form-handler');\nconst userForm = require('./user-form');\n\nmodule.exports = formHandler.create([\n    //...\n]).extends(userForm);\n```\n\n# Go further\n\n## Configuration\n\n```js\nform.config({\n  modelStrategy: new MongooseStrategy(User), // Or whatever strategy\n  validationByModel: false // true if you want to use the validate() method from the model if it has one.\n})\n```\n## Model Strategy\n\nYou can create your own model strategy by creating an object which extends the main strategy provided by this module: `express-form-handler-strategy`.\n\n## Rules \u0026 Formats\n\nYou can create your own field rule or field format by creating an object which extends the main rule or format object provided by this module: `formHandler.FieldRule` - `formHandler.FieldFormat`.\n\n### Create a new field rule\n\n```js\nconst Fieldrule = require('express-form-handler').FieldRule\n\nclass YourRule extends Fieldrule {\n  constructor (something) {\n    super()\n    this.name = 'myRule' // Optional...\n    this.something = something\n  }\n\n  check (field) {\n    if (field.value !== this.something) {\n      this.error = `The field ${field.label} ...`\n      return false\n    }\n\n    return true\n  }\n}\nmodule.exports = exports = YourRule\n```\n\n### Use your own field rule\n\n```js\nconst formHandler = require('express-form-handler');\nconst YourRule = require('./yourule')\n\nlet form = formHandler.create([\n  {\n    name: 'username',\n    label: 'Username',\n    format: formHandler.format.string(),\n    rules: [\n      formHandler.rule.required(), \n      formHandler.rule.minlength(4),\n      new YourRule(something)\n    ]\n  }, \n  // ...\n])\n\n// ...\n\n```\n\n### Create a new field format\n\n```js\nconst validator = require('validator')\nconst Fieldformat = require('express-form-handler').FieldFormat\n\nclass YourFormat extends FieldFormat {\n  constructor () {\n    super()\n    this.name = 'myFormat' // Optional...\n  }\n\n  check (field) {\n    if (!validator.isBase64(field.value)) {\n      this.error = `The field ${field.label} ...`\n      return false\n    }\n\n    return true\n  }\n}\nmodule.exports = exports = YourFormat\n```\n\n### Use your own field format\n\n```js\nconst formHandler = require('express-form-handler');\nconst YourFormat = require('./yourformat')\n\nlet form = formHandler.create([\n  {\n    name: 'username',\n    label: 'Username',\n    format: new YourFormat(),\n    rules: [\n      formHandler.rule.required(), \n      formHandler.rule.minlength(4)\n    ]\n  }, \n  // ...\n])\n\n// ...\n\n```\n\n# Contribute\n\nAll PR are welcome !  \nFeel free to open an issue if you found a bug or if you have an idea that can improve this package (new features, performance issues...).\n\n# Changelog\n\n\n## v2.0.0-beta\n- TODO: a ~100% test coverage\n- TODO: a better readme\n- IN PROGRESS: handle array field value (list, checkbox)\n- IN PROGRESS: provide a model sourcing config to avoid db query repetition in specific case (a user, after auth for exemple)\n- Make model strategy and each strategies an external npm package\n- Remove external stateless configuration to let form object handle it. It makes more sens to have a stateful configuration, and its easier to understand.\n- fix bugs from alpha\n\n## v2.0.0-alpha.x\n\nRewrite the module in order to have a more flexible way to personalized its behaviors with:\n  - model strategies\n  - formats/rules strategies. \n\nThat means, if something is missing for you in this package, you can create a new model strategy or create a new field format or rule. juste inherit your object with the corresponding strategy object which are exposed at the entry point of the module. \n\n## v1.2.x\n\n- Add model persitence\n\n## v1.1.3\n\n- Minor fix: readme, error in test...\n\n## v1.1.1 \u0026 v1.1.2\n\n- Important fix bug: no constraints checked in 1.1.0\n\n## v1.1.0\n\n- Add the custom constraint\n- Add support for array field value (checkbox, select (multiple)...)\n- Add async dependencies\n\n## v1.0.0\n\n- Remove the duty to create a new Form instance.\n- Add inheritance feature with `extend()` method.\n\n## v0.3.1\n\n- Fix custom error messages for constraint errors (equals to, required). I forgot to implement that :).\n- Add tests for this.\n\n## v0.3.0\n\n- Add custom error messages feature.\n- Fix i18n error. \n  - If the i18n error was already used by your project and configured, on showing translated error messages, that overwrite your i18n configuration settings.  \n  - Then, I removed i18n dependency for a simple require-dir on json files.\n- Add common.js file to handle some 'magic values' through constants system.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floulafripouille%2Fexpress-form-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floulafripouille%2Fexpress-form-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floulafripouille%2Fexpress-form-handler/lists"}