How to Use MediaWiki’s PageForms Extension to Create Custom Data Entry Forms

The form-building side of Page Forms: form markup, field types from text to combobox, autocomplete configuration, multi-instance templates and conditionals.

The Page Forms quick start — Special:CreateClass — gets a basic form working in minutes. This article is the next level: the actual form markup language, the field types that make forms pleasant, and the patterns for real data models. It complements the earlier installation guide on this blog; here we assume the extension is running (current version 6.x) with a storage backend chosen (Cargo or Semantic MediaWiki).

The form page structure

A form lives in the Form: namespace and is plain wikitext. The skeleton:

This is the form description, shown on the form page.

<noinclude>
{{#forminput:form=BookEntry|size=30}}
</noinclude>

{{{for template|BookEntry}}}
{| class="formtable"
! Title:
| {{{field|Title|mandatory}}}
! Author:
| {{{field|Author|input type=combobox|values from category=Authors}}}
! Year:
| {{{field|Year|input type=year|input type=text|size=4}}}
|}
{{{end template}}}

{{{standard input|summary}}}
{{{standard input|save}}}

{{#forminput:...}} places the 'add new' link; {{{for template|...}}} opens the block for one template; {{{field|...}}} defines form fields; {{{standard input|...}}} adds save/summary controls.

Field types that matter

  • input type=text — default; add mandatory, default=..., size=, maxlength=
  • input type=textarea — free text; rows=6|cols=60, optional VisualEditor/basic toolbar via editor=wikieditor
  • input type=combobox with values from category=Authors or values from namespace=Project — type-as-you-go suggestions over existing values; the backbone of consistency
  • input type=checkbox, input type=radiobutton (with values=...), input type=dropdown — fixed-choice fields
  • input type=date / input type=datetimepicker — dates without format fights
  • input type=year, input type=number, input type=rating — numeric inputs; min=/max= for bounds
  • input type=googlemaps / openlayers / leaflet, and input type=map — coordinates
  • input type=upload (with uploadable) — file upload into the form
  • input type=hidden — values filled automatically

Type validation: with Cargo/SMW the declared type of the stored field drives validation; with Page Forms alone, use input type=... constraints (e.g. integer) to reject junk at entry.

Autocomplete sources

| {{{field|Author|input type=combobox|values from category=Authors}}}
| {{{field|Product|input type=combobox|values from namespace=Products|show on select=Details}}}

values from category=, values from namespace=, values from external data= (with the External Data extension) and remote autocomplete via autocomplete=remote cover most needs; $wgPageFormsAutocompleteCacheTimeout (default 300 s) controls freshness of the cached suggestions.

Multiple instances: one form, many records

Repeatable sections let one page hold several records of the same template — e.g. a product page with multiple SKUs:

{{{for template|Sku|multiple|label=Add another SKU}}}
! SKU:
| {{{field|SkuCode}}}
! Price:
| {{{field|Price|input type=number}}}
{{{end template}}}

The multiple keyword adds add/remove controls; each instance becomes a template call on the page. Limits and default instance counts are parameters of multiple (min instance=1, max instance=5).

Conditional fields

Show fields only when they apply:

! Paid subscription?
| {{{field|IsPaid|input type=checkbox}}}
! License key
| {{{field|LicenseKey|show on select=IsPaid=>1}}}

show on select (and hide on select) toggle fields based on a dropdown/checkbox value; the mapping syntax FieldName=>value supports multiple conditions. This keeps forms short — the single most effective usability measure.

Form-to-template contract

The form is only the input surface; the template must store what the form sends. With Cargo: {{#cargo_store: _table=Books |Author={{{Author|}}} ...}}; with SMW: [[Has author::{{{Author|}}}| ]]. Mismatch between form field names and template parameters is the most common Page Forms bug — field names must match template parameters exactly (or use params= in for template to map).

The Defining forms documentation is the full reference, including every input type's parameters. Start with one template and one form, add conditionals and multiple instances as the data model demands — forms grow best with the model, not before it.

Subscribe to MediaWiki Tips and Tricks

Don’t miss out on the latest articles. Sign up now to get access to the library of members-only articles.
jamie@example.com
Subscribe