Template:Form

From mediawiki.org
Template documentation


Use this template to create forms that can create pages or add content to existing pages.

Parameters[edit]

General[edit]

The following parameters control the general behavior of the form:

  • templateRequired! Name of the template that will process and format the submitted data. If you don't want to use a template (or if you want to use several templates) then you can create a template meant to be substituted and set subst:Your template as the value of this parameter.
  • page — Name of the page where the data will be posted. If the page doesn't exist, it will be created. If the page exists, the data will be appended. If omitted, the current page will be used. If the given page name contains a string like "{{{x}}}", it will be replaced with the value of the field named "x". This allows to build page names dynamically by combining predefined text and field values.
  • section — Name of the section where the data will be posted. If the section doesn't exist, it will be created. If the section exists, the data will be appended. If omitted, but one of the fields is named "section", then the value of that field will be used. Else, the data will be appended to the end of the page. If the given section name contains a string like "{{{x}}}", it will be replaced with the value of the field named "x". This allows to build section names dynamically by combining predefined text and field values.
  • redirect — Set this to any value to redirect the user to the page (and section) where the data was posted. If omitted, then a success message defined by submit-success (see below) will be shown instead.

Fields[edit]

The following parameters control the form fields:

  • fieldN (replacing N for a number from 0 to 99) — Name of the field. This will also be the name of the parameter fed to the template. If you want to use anonymous parameters, just name them using numbers (e.g. field1 = 1). If no fields are defined, then the template will be injected with no parameters.
  • fieldN-label — Label of the field.
  • fieldN-value — Default value of the field.
  • fieldN-placeholder — Placeholder of the field.
  • fieldN-help — Help text of the field.
  • fieldN-help-inline — Whether the help text should be shown inline. Any value means yes.
  • fieldN-required — Whether the field is required. Any value means yes.
  • fieldN-disabled — Whether to disable the field. Any value means yes.
  • fieldN-type — Type of the field. Supported values are:
    • text — Use it for plain text inputs. This is the default field type.
    • page — Use it for page title inputs. The form will suggest existing titles as the user types. Use fieldN-namespace and fieldN-category to limit the titles suggested.
    • textarea — Use it for multi-line text inputs.
    • location — Use it for location inputs. The form will suggest locations as the user types, using Open Street Map's Nominatim service.
    • number — Use it for number inputs. Use fieldN-min and fieldN-max to limit the allowed numbers.
    • dropdown — Use it for dropdown menus. Use fieldN-options to set the allowed options. If fieldN-required is not set, then an additional empty option will be included, using fieldN-placeholder as the label.
    • radio — Use it for radio select inputs. Use fieldN-options to set the allowed options. If fieldN-required is not set, then an additional empty option will be included, using fieldN-placeholder as the label.
    • boolean — Use it for boolean inputs. Boolean inputs render as a single checkbox. If the checkbox is checked, then the value of fieldN-value will be posted, or "1" if no value is set. If the checkbox is not checked, then no value will be posted. Use fieldN-selected to control the initial state of the checkbox.
    • hidden — Use it for hidden inputs.
  • fieldN-min — Sets a minimum value for fields of type "number".
  • fieldN-max — Sets a maximum value for fields of type "number".
  • fieldN-selected — Sets the initial state for fields of type "boolean".
  • fieldN-options — Comma-separated list of options for fields of type "dropdown" or "radio".
  • fieldN-category — Limits the suggestions for fields of type "page" to this category.
  • fieldN-namespace — Limits the suggestions for fields of type "page" to this namespace number. Defaults to the main namespace.

Messages[edit]

The following parameters control the form messages:

  • submit — Text of the Submit button. Default is "Submit".
  • submit-success — Text to show when the data is successfully submitted. Default is "The form was submitted, thanks!"
  • submit-error — Text to show if an unknown error occurs when submitting the data. Default is "Something went wrong, sorry!"
  • template-error — Text to show if the required template parameter is not set. Default is "The template parameter is required."
  • namespace-error — Text to show if a form is submitted in the Template namespace. Default is "Forms don't work in the Template namespace."
  • group-error — Text to show if the group parameter is set but the user is not part of the group. Default is "This form is restricted to the '$1' group."

Examples[edit]

Simple[edit]

The following form would inject a call to Template:Message at the bottom of Sandbox:

{{Form
| template = Message
| page = Sandbox
| field1 = name
| field1-label = Your name
| field2 = text
| field2-label = Your message
| field2-type = textarea
| field2-required = required
}}
Loading...

Advanced[edit]

The following form would inject a call to Template:Message at the bottom of the talk page of the page entered in the first field, under the section entered in the second field, and the user would then be redirected to it:

{{Form
| template = Message
| page = Talk:{{{page}}}
| section = {{{topic}}}
| redirect = yes
| field1 = page
| field1-label = Page
| field1-type = page
| field2 = topic
| field2-label = Topic
| field3 = name
| field3-label = Name
| field4 = address
| field4-label = Location
| field4-type = location
| field5 = text
| field5-label = Message
| field5-type = textarea
| field5-required = required
| field6 = terms
| field6-label = I accept the terms and conditions
| field6-type = boolean
| field6-required = required
}}
Loading...

See also[edit]