How to Use MediaWiki’s PageForms Extension to Create Custom Data Entry Forms
The PageForms extension turns a MediaWiki installation into a lightweight data‑entry platform
Why PageForms?
The PageForms extension turns a MediaWiki installation into a lightweight data‑entry platform. By defining forms in the Form: namespace you can let any user create or edit pages that are backed by infobox‑style templates, without writing a single line of PHP. The extension works on its own, or in concert with Semantic MediaWiki or Cargo for structured querying.
1. Install PageForms
Optionally configure rights (e.g. only admins see the “edit with form” tab):
$wgGroupPermissions['*']['viewedittab'] = false;
$wgGroupPermissions['sysop']['viewedittab'] = true;Run the update script to register the new tables:
php maintenance/update.phpAdd the loader line to LocalSettings.php:
wfLoadExtension( 'PageForms' );Download the extension (Git, zip or Composer). The simplest method is Composer:
composer require mediawiki/page-forms "^6.0"2. Quick‑Start with Special:CreateClass
If you have SMW or Cargo installed, the helper page Special:CreateClass can generate a complete data class – template, form and category – in one go.
- Visit
Special:CreateClass. - Fill in the class name (e.g. Book) and add the fields you need.
- Submit – the extension creates
Template:Book,Form:BookandCategory:Booksautomatically.
If you prefer a manual approach, read on.
3. Define the Underlying Template
Templates hold the actual markup that will appear on the data pages. They also define the semantic or Cargo properties that store the values.
{{{!}} class="infobox"
|-
! Title !! {{{title}}}
|-
! Author !! {{{author|}}}
|-
! Genre !! {{{genre|}}}
|-
! Year !! {{{year|}}}
|}
{{#if:{{{free text|}}}|{{{free text}}}}Key points:
- Each
{{{field}}}corresponds to a form field. - Optional fields can have a default after the pipe (e.g.
{{{author|}}). - Anything outside the template (the
#ifblock) is treated as “free text” – a large textarea that PageForms will preserve.
4. Create the Form Definition
Form definitions live in the Form: namespace and use a simple markup language. Below is a minimal Form:Book that mirrors the template above.
{{{info|add title=Add a new book|edit title=Edit book "{{{page name}}}"}}}
{{{for template|Book}}}
|-
! Title:
| {{{field|title|mandatory|input type=text|size=50}}}
|-
! Author:
| {{{field|author|input type=combobox|values from category=Authors}}}
|-
! Genre:
| {{{field|genre|input type=combobox|values from category=Genres}}}
|-
! Year:
| {{{field|year|input type=year|default=now}}}
{{{end template}}}
'''Notes''' (free‑text):
{{{standard input|free text}}}
{{{standard input|save|label=Save book}}}
{{{standard input|preview}}}
{{{standard input|cancel}}}Explanation of the most common tags:
{{{info|…}}}– sets the page title for the add/edit screens.{{{for template|TemplateName}}}– tells PageForms which template the fields belong to.{{{field|name|…}}}– defines a single input. Common parameters:mandatory– forces a value.input type=…– overrides the auto‑detected type (see the Input Types section).values from category=…– provides a static list taken from a category, useful for autocompletion.default=…– default value for new pages.
{{{standard input|…}}}– adds the usual buttons; omitting any of them hides that button.
5. Input Types at a Glance
PageForms supports a rich set of HTML‑like inputs. The most useful for data entry are:
| Type | When to use |
|---|---|
text | Simple one‑line strings. |
textarea | Longer free‑form text. |
combobox | Autocomplete with a dropdown (ideal for categories). |
tokens | Multiple values that should appear as removable “chips”. |
dropdown | Fixed list where only one value can be chosen. |
checkboxes | Multiple selections from a static list. |
listbox | Large multiple‑select box. |
tree | Hierarchical selection (categories or custom structures). |
date, year, datepicker | Date entry – pick one that matches your UI preference. |
rating | Star‑based rating (e.g. for reviews). |
googlemaps, leaflet, openlayers | Geographic coordinates – requires an API key unless disabled. |
Each type has its own set of parameters; the full list lives on the Input Types page.
6. Advanced Form Features
6.1 Multiple‑Instance Templates (Repeating Sections)
When a page can contain any number of sub‑objects (e.g. a book with multiple reviews), add the multiple flag to the for template tag.
{{{for template|Review|multiple|add button text=Add another review}}}
! Reviewer:
| {{{field|reviewer|input type=combobox|values from category=Users}}}
! Rating:
| {{{field|rating|input type=rating}}}
! Comment:
| {{{field|comment|input type=textarea}}}
{{{end template}}}The result is a set of “Add another” buttons that dynamically insert new instances.
6.2 Spreadsheet‑Style Editing
Large repeatable tables become easier to edit with the display=spreadsheet parameter.
{{{for template|Ingredient|multiple|display=spreadsheet|height=300}}}
{{{field|name}}}
{{{field|quantity}}}
{{{field|unit|input type=dropdown|values=kg|g|ml}}}
{{{end template}}}This renders the rows as a JSpreadsheet grid, allowing bulk copy‑paste.
6.3 Calendar Editing
For events with a start/end date, use display=calendar. The user sees a full‑screen calendar where each row becomes an event.
{{{for template|Event|multiple|display=calendar|event title field=title|event start date field=start|event end date field=end}}}
{{{field|title}}}
{{{field|start|input type=datetime}}}
{{{field|end|input type=datetime}}}
{{{end template}}}6.4 Wizard‑Style Forms
Split a long form into logical screens using <div class="pf-wizard-screen"> wrappers.
{{{field|title|mandatory}}}
{{{field|author}}}
{{{field|genre}}}
{{{field|year|input type=year}}}
{{{standard input|save|label=Create book}}}
The wizard automatically shows one screen at a time and remembers the values.
6.5 Tabbed Sections (Header Tabs Extension)
If the Header Tabs extension is installed, you can turn top‑level sections into tabs simply by adding <headertabs/> before the standard inputs.
7. Linking to Forms
There are three primary parser functions for getting users to a form:
#formlink– a normal link that opens the form.#formredlink– makes red links (non‑existent pages) point to the form automatically.#queryformlink– for linking to a query form (see next section).
Example of a link that creates a new Book page:
{{#formlink:form=Book|link text=Add a new book}}And an auto‑redlink for a missing author page:
{{#formredlink:form=Author|link text=Create author}}8. Query Forms – Turning Data into Reports
PageForms also powers “query forms” that let users search the stored data. The workflow mirrors a normal form, but the target page is Special:RunQuery instead of a content page.
{{{info|query title=Search books|query form at top}}}
{{{for template|Book}}}
! Title contains:
| {{{field|title|input type=text|placeholder=Partial title}}}
! Author is:
| {{{field|author|input type=combobox|values from category=Authors}}}
! Year after:
| {{{field|year|input type=year|default=2000}}}
{{{end template}}}
{{{standard input|run query|label=Search}}When the user clicks “Search”, the form runs any Semantic MediaWiki or Cargo queries embedded in Template:Book and displays the results on the same page.
Link to the query form with #queryformlink:
{{#queryformlink:form=Book|link text=Find books}}9. Performance Tips
- Keep the number of
values from categorylists reasonable – large categories can slow autocompletion.
Disable external map services on private wikis:
$wgPageFormsDisableOutsideServices = true;Cache form definitions if your forms are static:
$wgPageFormsCacheFormDefinitions = true;
$wgPageFormsFormCacheType = CACHE_ANYTHING;Cache autocomplete values – add to LocalSettings.php:
$wgPageFormsCacheAutocompleteValues = true;
$wgPageFormsAutocompleteCacheTimeout = 86400; // 1 day10. Full Example – A Mini Library
Below is a concise, ready‑to‑paste set of pages that implements a “Books” and “Authors” data model, using PageForms only (no SMW/Cargo). It demonstrates templates, forms, multiple‑instance reviews, and a query form.
Special:RunQuery – Book search
{{{info|query title=Search books|query form at top}}}
{{{for template|Book}}}
! Title contains:
| {{{field|title|input type=text|placeholder=Partial title}}}
! Author is:
| {{{field|author|input type=combobox|values from category=Authors}}}
! Year after:
| {{{field|year|input type=year|default=2000}}}
{{{end template}}}
{{{standard input|run query|label=Search}}Form:Author
{{{info|add title=Add an author|edit title=Edit author "{{{page name}}}"}}}
{{{for template|Author}}}
! Name:
| {{{field|name|mandatory|input type=text|size=40}}}
! Country:
| {{{field|country|input type=text|size=30}}}
{{{end template}}}
'''Bio''' (free‑text):
{{{standard input|free text}}}
{{{for template|WrittenBook|multiple|label=Books written|add button text=Add book}}}
! Book title:
| {{{field|booktitle|input type=combobox|values from category=Books}}}
{{{end template}}}
{{{standard input|save|label=Save author}}}
{{{standard input|preview}}}
{{{standard input|cancel}}}Template:Author
{{{!}} class="infobox"
|-
! Name !! {{{name}}}
|-
! Country !! {{{country|}}}
|}
{{#if:{{{free text|}}}|{{{}}}}
{{#if:{{{booklist|}}}|{{{booklist}}}}Form:Book
{{{info|add title=Add a new book|edit title=Edit book "{{{page name}}}"}}}
{{{for template|Book}}}
! Title:
| {{{field|title|mandatory|input type=text|size=60}}}
! Author:
| {{{field|author|input type=combobox|values from category=Authors}}}
! Genre:
| {{{field|genre|input type=combobox|values from category=Genres}}}
! Year:
| {{{field|year|input type=year|default=now}}}
{{{end template}}}
'''Notes''' (free‑text):
{{{standard input|free text}}}
{{{for template|Review|multiple|label=Reviews|add button text=Add review}}}
! Reviewer:
| {{{field|reviewer|input type=combobox|values from category=Users}}}
! Rating:
| {{{field|rating|input type=rating}}}
! Comment:
| {{{field|comment|input type=textarea}}}
{{{end template}}}
{{{standard input|save|label=Save book}}}
{{{standard input|preview}}}
{{{standard input|cancel}}}Template:Book
{{{!}} class="infobox"
|-
! Title !! {{{title}}}
|-
! Author !! {{{author|}}}
|-
! Genre !! {{{genre|}}}
|-
! Year !! {{{year|}}}
|}
{{#if:{{{free text|}}}|{{{free text}}}}
{{#if:{{{review|}}}|{{{review}}}}Copy each block to the corresponding page (remember the Form: and Template: namespaces) and you have a fully functional library system – users can add books, authors, reviews, and search the collection without ever touching wikitext directly.
11. Next Steps
- Explore the full form syntax for tabs, wizards, and embedded templates.
- If you need more sophisticated queries, enable Semantic MediaWiki or Cargo and use their query language inside your templates.
- Consider the Page Schemas extension for bulk generation of classes.
With PageForms you can turn any MediaWiki into a structured data entry portal, a catalog, a survey system, or even a lightweight ticket tracker – all while keeping the familiar wiki editing experience.