Skip to content

cezary/JSONForms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONForms

An implementation of the algorithm outlined here for submitting form data as JSON. Convert any form into a structured JSON object.

Submitting this form

<form enctype='application/json'>
  <input name='places[0][city]' value='New York City'>
  <input type='number' name='places[0][population]' value='8175133'>
  <input name='places[1][city]' value='Los Angeles'>
  <input type='number' name='places[1][population]' value='3792621'>
  <input name='places[2][city]' value='Chicago'>
  <input type='number' name='places[2][population]' value='2695598'>
</form>

uploads this object

{
  "places": [
    {
      "city": "New York City",
      "population": 8175133
    },
    {
      "city": "Los Angeles",
      "population": 3792621
    },
    {
      "city": "Chicago",
      "population": 2695598
    }
  ]
}

Usage:

Include the script in your page and any form with an attribute of enctype set to 'application/json' will submit data with a json payload.

To disable json post submission

JSONForms.disable()

To enable

JSONForms.enable()

To create a JSON object of a form

JSONForms.encode(formElement)

TODO

  • Add support for file input types
  • Add support for other input elements like radios, textareas

About

Submit forms as json

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published