< Markup expressions | Documentation Index | Simultaneous edits >

This page explains how you can embed input forms into wiki pages. Input forms don't actually handle processing of the form data -- the feature simply allows creation of forms inside wiki pages. Forms processing can be found in the Cookbook (see below).

Markup

Two directives are used to begin and end forms:

    (:input form "url" method:)
    ...
    (:input end:)

The (:input form:) directive starts a form that will post to url (optional action=url) using the supplied method (optional method=method). The url must be in quotes if not specified via action=. If the url is omitted, then the current page is assumed. If method is omitted then "POST" is assumed. An optional name="FormName" argument can be used to name the form. You can explicitly state action=url or method=get or you can simply use them as positional parameters.

If your site uses ?n=Group.Page to specify the pagename then having a field (:input hidden name=n value={$FullName}:) will allow your form to post to the current page as an alternative to fully specifying the action=url.

The (:input end:) directive ends the current form.

Note that this feature doesn't ensure that the form output is correct HTML -- it assumes the author knows a little bit of what he or she is doing. Notably, (:input form:) and (:input end:) shouldn't appear inside tables, and all form fields and controls should be inside an (:input form:)...(:input end:) block. Also note that not all browsers support all field types - as of 2023, the (:input month:) field is still unsupported by desktop Firefox and Safari.

Standard input controls

The standard input controls are:

    (:input text name "value" size=n:) 
    (:input hidden name "value":) 
    (:input password name "value":) 
    (:input search name "value":) 
    (:input number name "value" min=x max=y step=z:) 
    (:input email name "value":) 
    (:input tel name "value":) 
    (:input url name "value":) 
    (:input date name "value":) 
    (:input month name "value":) 
    (:input color name "value":) 
    (:input radio name "value" "label" checked=checked:) 
    (:input checkbox name "value" "label" checked=checked:) 
    (:input select name "value" "label":)  - see select
    (:input datalist id "value":)  - see datalist
    (:input default default-name "default-value":)   - see  default
    (:input textarea name [=value=] rows=n cols=n:) 
    (:input file name "label":) 
    (:input image name "src" "alt":) 
    (:input reset name "label":) 
    (:input button name "value":) 
    (:input pmtoken:)  - see pmtoken
    (:input submit name "value":) 

Where name and value are in the HTML syntax: name="addr" value="808 W Franklin".

A PmWiki-specific input control is "e_author" which will be pre-filled with the current author name, and if $EnablePostAuthorRequired is set, will have a required="required" attribute:

    (:input e_author:)  

For most controls the markup has the form:

    (:input type name "value" parameter="value":) 

where type is the type of input element (described below), name is the name of the control, value is its initial value, and parameters are used to specify additional attributes to the control. If value contains spaces, enclose it in quotes; if it contains newlines (for textarea and hidden elements), enclose it in [=...=].

For example, the following creates a text input control with a size of 30 characters:

(:input text authorid "Jane Doe" size=30:)

For convenience, an author can also specify name and value arguments directly using name= and value= attributes (same as HTML):

(:input text name=authorid value="Jane Doe" size=30:)

For the textarea control a value can be set from PmWiki 2.2.0beta45 onwards. Enclose the value in [=...=] if it contains spaces or new lines.

The submit control will more often be written as:

    (:input submit value="label":) 

Here's a more complete example, e.g., for a login prompt:

(:input form "https://www.example.com":)
(:input hidden action login:)
||     Name:||(:input text username:)         ||
|| Password:||(:input password password:)     ||
||          ||(:input checkbox terms yes "Accept Terms" required=required:) ||
||          ||(:input submit value="Log In":) ||
(:input end:)

Name:
Password:
 
 

General form field attributes

(:input button bname "Delete all pages" data-pmconfirm="Are you sure you want to delete all pages? This cannot be undone.":)

(:input select ... :)

The basic form of a select box is a sequence of options:

(:input form:)
(:input select name=abc value=1 label=alpha :)
(:input select name=abc value=2 label=beta  :)
(:input select name=abc value=3 label=gamma :)
(:input submit:)
(:input end:)

The values can be specified positionally:

 (:input select abc 1 alpha :)

We can specify the size of the selection box:

 (:input select abc 1 alpha size=3 :)

You can specify a multiple select box (only the first item needs to have "size=3 multiple" attributes):

 (:input select abc 1 alpha size=3 multiple:)

To have an element selected, use selected=selected:

 (:input select abc 2 beta selected=selected:)

Note that to have two select boxes inline, not only should you give them different name= parameters, but also place a separator, like a character, &nbsp; or even the null sequence [==] between them:

(:input form:)
(:input select name=FIRST value=1:)(:input select name=FIRST value=2:)[==]
(:input select name=SECOND value=3:)(:input select name=SECOND value=4:)
(:input end:)

Note, in the HTML output, only the attributes label, value and selected are applied to the <option> HTML tag. Any other attributes, including name, id, class and title are applied to the wrapping <select> HTML tag, and later definitions replace previous ones.

(:input datalist ... :)

This allows a number of values (suggestions) to appear in a drop-down menu allowing the user to select one of the values or to fill a new, different value. The markup accepts named or positional attributes:

  (:input datalist id "value":) 
  (:input datalist id=id value="value":) 

An existing (:input text:) field needs to have an attribute list=id_of_the_datalist to attach the suggestions.

The datalist element is invisible and can be anywhere in the page. The suggestion menu appears when the user starts typing in the attached text field and filters the suggested values that contain the letters typed in the text field.

Type a browser name: (:input text browsers list=dlist_id :)
(:input datalist dlist_id Firefox:)
(:input datalist dlist_id Chrome:)
(:input datalist dlist_id Safari:)
(:input datalist dlist_id Edge:)
(:input datalist dlist_id MSIE:)
(:input datalist dlist_id Opera:)
(:input datalist dlist_id Lynx:)

Type a browser name:

This is a recent addition to the HTML standard, see https://caniuse.com/#feat=datalist for current browser support.

Note that if you have a datalist element immediately following another datalist element, not only should you give them different id= attributes, but also place a separator, like a character, &nbsp; or the null sequence [==] between them:
(:input datalist dl_1 First:)
(:input datalist dl_1 Second:)[==]
(:input datalist dl_2 First:)
(:input datalist dl_2 Second:)

(:input pmtoken:)

This includes a unique session identifier as a hidden input field to prevent cross-site request forgeries (CSRF). Can be included in custom forms, and the custom action handlers receiving the form can check if the request is valid by calling pmtoken(1).

The "name" of the HTML input element, by default 'pmtoken', can be changed by setting for example $FmtV['$TokenName'] = 'myCSRFtoken';. In your form you still need to have (:input pmtoken:) which will use the new name for the HTML element.

See Also

Compatible recipes:

< Markup expressions | Documentation Index | Simultaneous edits >


This page may have a more recent version on pmwiki.org: PmWiki:Forms, and a talk page: PmWiki:Forms-Talk.

PmWiki/

Forms