Skip to Content search facebook instagram pinterest twitter youtube

JsonForm

A JSON form is a form where the fields and their validation are all configured in a JSON file. In that file, top level keys are tab names, with each tab mapping to either an array of fields and other items - including multiedits, or simply a category selection.

There is a (almost) complete example of JsonForm available in the Demo module, which can also be used as a reference.

Tabs

The JSON file is an array of tabs to display, with the key being the tab name and the value being an array of items.

{
    "Details": [
        /* items go here */
    ],
    "Images": [
        /* more items go here */
    ],
    "Categories": "categories"
}

Multiple tabs can be specified, and each tab can have multiple items. If only one tab is specified, the tabs bar is automatically hidden.

The special string value "categories" can be used instead of an array of tab items. This will output a category selection interface.

Items

There are a number of item types available. Each item is a double-nested array with the type as the key and the details as the value.

{
    "Details": [
        {
        	"field": {
        		/* field settings go here */
        	}
        },
        {
        	"field": {
        		/* another field goes here */
        	}
        }
    ]
}

Some item types such as multiedits and groups can also have nested sub-items. These behave in the same way as top-level tab items.

Item types

Item types include:

Fields, using the field type

Headings, using the heading type

Arbitrary HTML content, using the html type

Multiedits (multiple javascript-managed subrecords), using the multiedit type

Execute PHP functions, using the func type

Groups of fields wrapped in additional divs, using the group type

Autofill lists for quick selection of related ids, using the autofill type