How to Use Page Forms Extension to Create Custom Data Entry Forms in MediaWiki

Why Page Forms?

The Page Forms extension (formerly Semantic Forms) lets you turn any infobox‑style template into a user‑friendly form. It works on its own, or together with Semantic MediaWiki or Cargo for data storage and querying. With Page Forms you can let editors add, edit and query structured data without touching wikitext.

Installation Basics

Optionally grant the createclass right to users who should be able to create new data structures:

$wgGroupPermissions['user']['createclass'] = true;

Run the update script to register new tables:

php maintenance/update.php

Add the loader line to LocalSettings.php:

wfLoadExtension( 'PageForms' );

Download the extension (recommended via Composer):

composer require mediawiki/page-forms ^6.0

or clone the repository into extensions/PageForms.

Data Model First: Templates and Properties

Page Forms works by filling a template. Define the data you want to capture as a template, optionally backed by SMW properties or Cargo fields.

Example: A simple "Book" entry

{{#if:{{{title|}}}|[[Has title::{{{title}}}]]}}
{{#if:{{{author|}}}|[[Has author::{{{author}}}]]}}
{{#if:{{{year|}}}|[[Published year::{{{year}}}]]}}
{{#if:{{{genre|}}}|[[Has genre::{{{genre}}}]]}}

Save this as Template:Book. If you are using Semantic MediaWiki, create matching properties (Property:Has title, etc.) with the appropriate data types.

Defining the Form

Form definitions live in the Form: namespace. The syntax uses triple curly braces. A minimal form for the Book template looks like this:


This is the Book form. Enter a page name below; if the page exists you will edit it, otherwise a new page will be created.
{{#forminput:form=Book}}



{{{for template|Book}}}
{| class="formtable"
! Title || {{{field|title|input type=text|mandatory}}}
|- 
! Author || {{{field|author|input type=combobox|values from category=Authors}}}
|- 
! Year || {{{field|year|input type=year}}}
|- 
! Genre || {{{field|genre|input type=dropdown|values=Fiction,Non‑fiction,Science,History}}}
|}
{{{end template}}}
{{{standard input|free text|rows=8}}}
{{{standard input|summary}}}
{{{standard input|watch}}}
{{{standard input|save}}}
{{{standard input|preview}}}

Key elements:

  • {{{for template|Book}}} tells the form which template to populate.
  • {{{field|name|input type=…}} defines each field. The input type can be text, textarea, combobox, dropdown, date, year, checkbox, etc. See the extension documentation for the full list.
  • mandatory makes a field required.
  • Standard inputs (free text, summary, save, …) control the bottom part of the form.

Enabling the “Edit with form” Tab

There are three ways to make the form appear when a user clicks the edit tab:

  1. Namespace based: Create a page MyWiki:Main (or the target namespace) and add #default_form:Book.
  2. Page based: Insert {{#default_form:Book}} on an individual page.

Category based: Add a category to the template and set the default form on that category.

[[Category:Books]]
[[Has default form::Book]]

Category‑based is usually preferred because it automatically applies to every page using the template.

Linking to Forms

To let users create a new page with a specific form, use the parser function #forminput (already shown in the noinclude section) or #formlink for a direct link.

{{#formlink:form=Book|link text=Add a new book|query string=Book[author]={{PAGENAME}}}}

This creates a button that opens the Book form and pre‑fills the author field with the current page name.

Advanced Field Options

Page Forms supports many parameters to tailor the user experience.

  • values= – hard‑coded list of allowed values.
  • values from category= – pull values from a category (useful for dynamic lists).
  • values from property= – autocomplete based on a SMW property.
  • default= – set a default value (e.g. default=now for dates).
  • list – indicate the field holds a list; combine with delimiter=; if you need a custom separator.
  • uploadable – add a file‑upload widget (useful for images).
  • show on select= – hide or reveal other page elements based on the chosen value.

Example of a tokenised, multi‑value field with autocompletion from a category:

{{{field|keywords|input type=tokens|list|values from category=Keywords|placeholder=Add keywords}}}

Creating Query Forms

Query forms let users search existing data without editing pages. Use the special page Special:RunQuery and point it at a template that contains SMW #ask queries.

{{#info|query title=Find books}}
{{{for template|BookQuery}}}
{| class="formtable"
! Author || {{{field|author|input type=combobox|values from category=Authors}}}}
|- 
! Year || {{{field|year|input type=year}}}
|}
{{{end template}}}
{{{standard input|run query|label=Search}}}

The corresponding Template:BookQuery would contain an #ask that uses the supplied parameters.

Permissions and Customisation

Page Forms defines four user rights:

  • createclass – create new classes via Special:CreateClass.
  • editrestrictedfields – edit fields marked restricted.
  • multipageedit – use the spreadsheet‑like Special:MultiPageEdit.
  • viewedittab – see the “edit with form” tab.

Adjust them in LocalSettings.php as needed. For example, to hide the tab for anonymous users:

$wgGroupPermissions['*']['viewedittab'] = false;
$wgGroupPermissions['sysop']['viewedittab'] = true;

Putting It All Together – A Mini‑Tutorial

  1. Install Page Forms (see above).
  2. Create the data template (Template:Event) with SMW properties for Event date, Location, Type.
  3. Define the form (Form:Event) using appropriate field types – a datepicker for the date, a combobox pulling values from the Category:Event types, and a textarea for description.
  4. Add [[Has default form::Event]] to the Category:Events page.
  5. Place a #forminput widget in the wiki’s sidebar (MediaWiki:Sidebar) so users can quickly add new events.
  6. Optionally, create a query form (Form:EventSearch) that lets users filter events by date range and type via Special:RunQuery.

After these steps, any user can click “Add a new event”, fill the form, and the resulting page will automatically contain the populated template and SMW properties, ready for querying and reporting.

Resources

  • Extension:Page Forms – MediaWiki (official documentation)
  • Special pages provided by Page Forms: Special:CreateClass, Special:CreateForm, Special:MultiPageEdit, Special:RunQuery
  • Parser function reference: #forminput, #formlink, #queryformlink, #autoedit

With these building blocks you can turn any MediaWiki installation into a powerful structured‑data entry system, all without writing PHP code. The combination of templates, SMW/Cargo, and Page Forms gives you a low‑code solution that scales from simple contact forms to complex multi‑instance data entry portals.

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