
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
form_to_object
Advanced tools
Convert a HTML form to an a JavaScript plain object (multi-dimensional).
Convert HTML forms with all their fields and values to multidimensional JavaScript objects
As a npm package:
npm install form_to_object
import formToObject from 'form_to_object';
// or
const formToObject = require('form_to_object');
As a JS script:
<!-- Include minified script (~6kb) -->
<script src="build/formToObject.js"></script>
<!-- jsdelivr (CDN) -->
<script src="
https://cdn.jsdelivr.net/npm/form_to_object@3.0.0/build/bundle/formToObject.min.js
"></script>
formToObject('myFormId');
formToObject(document.getElementById('myFormId'));
Resulted value:
{
"saveSettings": "Save",
"name": "Serban",
"race": "orc",
"settings": {
"input": "keyboard",
"video": {
"resolution": "1024x768",
"vsync": "on"
}
}
}
Good to know:
<form>
fields are found, but they lack of name
attribute property, the result will be {}
(empty object).<form>
contains only disabled
fields, the result will be {}
(empty object). If you force includeDisabledFields
then key:value pairs will be returned.<form>
will throw an Error.Option name | Default | Description |
---|---|---|
includeEmptyValuedElements | boolean (default false ) | Return field names as keys with empty value "" instead of just ignoring them. |
w3cSuccessfulControlsOnly | boolean (default false ) | TBA, WIP |
selectNameWithEmptyBracketsReturnsArray | boolean (default true ) | <select> field names like name="select[]" always return an array [a,b] instead or array of arrays [0: [a,b]] . |
checkBoxNameWithEmptyBracketsReturnsArray | boolean (default true ) | <input> checkboxes with field names like name=checkbox[] always return an array [a,b] instead or array of arrays [0: [a,b]] . |
IE 8, Firefox 3.5, Chrome, Safari, Opera 10, every mobile browser.
FAQs
Convert a HTML form to an a JavaScript plain object (multi-dimensional).
The npm package form_to_object receives a total of 2,276 weekly downloads. As such, form_to_object popularity was classified as popular.
We found that form_to_object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.