<commit_before># form2js
_Convenient way to collect form data into JavaScript object._

Example: http://form2js.googlecode.com/hg/example/test.html

If you have any questions/suggestions or find out something weird or illogical - feel free to post an issue.

## Details

Structure of resulting object defined by "name" attribute of form fields. See examples below.

This is **not** a serialization library. Library used in example for JSON serialization is http://www.json.org/js.html 

All this library doing is collecting form data and putting it in javascript object (obviously you can get JSON/XML/etc string by serializing it, but it's not an only purpose).

## Usage

### Objects/nested objects
Structure of resulting object defined in "name" attribute, delimiter is "." (dot) by default, but can be changed.

    <input type="text" name="person.name.first" value="John" />
    <input type="text" name="person.name.last" value="Doe" />

becomes

    {
        "person" :
        {
            "name" :
            {
                "first" : "John",
                "last" : "Doe"
            }
        }
    }

###Arrays
Several fields with the same name with brackets defines array of values.

    <label><input type="checkbox" name="person.favFood[]" value="steak" checked="checked" /> Steak</label>
    <label><input type="checkbox" name="person.favFood[]" value="pizza"/> Pizza</label><commit_msg>Edited README.markdown via GitHub<commit_after># form2js
_Convenient way to collect form data into JavaScript object._

Example: http://form2js.googlecode.com/hg/example/test.html

If you have any questions/suggestions or find out something weird or illogical - feel free to post an issue.

## Details

Structure of resulting object defined by "name" attribute of form fields. See examples below.

This is **not** a serialization library. Library used in example for JSON serialization is http://www.json.org/js.html 

All this library doing is collecting form data and putting it in javascript object (obviously you can get JSON/XML/etc string by serializing it, but it's not an only purpose).

## Usage
    form2object(rootNode, delimiter, skipEmpty, nodeCallback)

Values of all inputs under the _rootNode_ will be collected into one object (skipping empty inputs if _skipEmpty_ not false).

### Objects/nested objects
Structure of resulting object defined in "name" attribute, _delimiter_ is "." (dot) by default, but can be changed.

    <input type="text" name="person.name.first" value="John" />
    <input type="text" name="person.name.last" value="Doe" />

becomes

    {
        "person" :
        {
            "name" :
            {
                "first" : "John",
                "last" : "Doe"
            }
        }
    }

###Arrays
Several fields with the same name with brackets defines array of values.

    <label><input type="checkbox" name="person.favFood[]" value="steak" checked="checked" /> Steak</label>
    <label><input type="checkbox" name="person.favFood[]" value="pizza"/> Pizza</label>
{'fraction_non_alphanumeric': 0.10670630987776676, 'fraction_numerical': 0.0016518004625041295, 'mean_word_length': 3.282885431400283, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6224018', 'n_tokens_mistral': 874, 'n_tokens_neox': 825, 'n_words': 324}