[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/ -> form.php (summary)

DokuWiki XHTML Form

Author: Tom N Harris
License: GPL 2 (http://www.gnu.org/licenses/gpl.html)
File Size: 1147 lines (37 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Doku_Form:: (45 methods):
  __construct()
  startFieldset()
  endFieldset()
  addHidden()
  addElement()
  insertElement()
  replaceElement()
  findElementByType()
  findElementById()
  findElementByAttribute()
  getElementAt()
  getForm()
  printForm()
  addRadioSet()
  form_makeTag()
  form_makeOpenTag()
  form_makeCloseTag()
  form_makeWikiText()
  form_makeButton()
  form_makeField()
  form_makeFieldRight()
  form_makeTextField()
  form_makePasswordField()
  form_makeFileField()
  form_makeCheckboxField()
  form_makeRadioField()
  form_makeMenuField()
  form_makeListboxField()
  form_tag()
  form_opentag()
  form_closetag()
  form_openfieldset()
  form_closefieldset()
  form_hidden()
  form_wikitext()
  form_button()
  form_field()
  form_fieldright()
  form_textfield()
  form_passwordfield()
  form_filefield()
  form_checkboxfield()
  form_radiofield()
  form_menufield()
  form_listboxfield()


Class: Doku_Form  - X-Ref

Class for creating simple HTML forms.

The forms is built from a list of pseudo-tags (arrays with expected keys).
Every pseudo-tag must have the key '_elem' set to the name of the element.
When printed, the form class calls functions named 'form_$type' for each
element it contains.

Standard practice is for non-attribute keys in a pseudo-element to start
with '_'. Other keys are HTML attributes that will be included in the element
tag. That way, the element output functions can pass the pseudo-element
directly to buildAttributes.

See the form_make* functions later in this file.

Please note that even though this class is technically deprecated (use dokuwiki\Form instead),
it is still widely used in the core and the related form events. Until those have been rewritten,
this will continue to be used

__construct($params, $action = false, $method = false, $enctype = false)   X-Ref
Constructor

Sets parameters and autoadds a security token. The old calling convention
with up to four parameters is deprecated, instead the first parameter
should be an array with parameters.

param: mixed       $params  Parameters for the HTML form element; Using the deprecated
param: bool|string $action  (optional, deprecated) submit URL, defaults to current page
param: bool|string $method  (optional, deprecated) 'POST' or 'GET', default is POST
param: bool|string $enctype (optional, deprecated) Encoding type of the data
author: Tom N Harris <tnharris@whoopdedo.org>

startFieldset($legend)   X-Ref
startFieldset

Add <fieldset></fieldset> tags around fields.
Usually results in a border drawn around the form.

param: string  $legend Label that will be printed with the border.
author: Tom N Harris <tnharris@whoopdedo.org>

endFieldset()   X-Ref
endFieldset

author: Tom N Harris <tnharris@whoopdedo.org>

addHidden($name, $value)   X-Ref
addHidden

Adds a name/value pair as a hidden field.
The value of the field (but not the name) will be passed to
formText() before printing.

param: string  $name   Field name.
param: string  $value  Field value. If null, remove a previously added field.
author: Tom N Harris <tnharris@whoopdedo.org>

addElement($elem)   X-Ref
addElement

Appends a content element to the form.
The element can be either a pseudo-tag or string.
If string, it is printed without escaping special chars.   *

param: string|array  $elem   Pseudo-tag or string to add to the form.
author: Tom N Harris <tnharris@whoopdedo.org>

insertElement($pos, $elem)   X-Ref
insertElement

Inserts a content element at a position.

param: string       $pos  0-based index where the element will be inserted.
param: string|array $elem Pseudo-tag or string to add to the form.
author: Tom N Harris <tnharris@whoopdedo.org>

replaceElement($pos, $elem)   X-Ref
replaceElement

Replace with NULL to remove an element.

param: int          $pos  0-based index the element will be placed at.
param: string|array $elem Pseudo-tag or string to add to the form.
author: Tom N Harris <tnharris@whoopdedo.org>

findElementByType($type)   X-Ref
findElementByType

Gets the position of the first of a type of element.

param: string  $type   Element type to look for.
return: int|false     position of element if found, otherwise false
author: Tom N Harris <tnharris@whoopdedo.org>

findElementById($id)   X-Ref
findElementById

Gets the position of the element with an ID attribute.

param: string  $id     ID of the element to find.
return: int|false     position of element if found, otherwise false
author: Tom N Harris <tnharris@whoopdedo.org>

findElementByAttribute($name, $value)   X-Ref
findElementByAttribute

Gets the position of the first element with a matching attribute value.

param: string  $name   Attribute name.
param: string  $value  Attribute value.
return: int|false     position of element if found, otherwise false
author: Tom N Harris <tnharris@whoopdedo.org>

getElementAt($pos)   X-Ref
getElementAt

Returns a reference to the element at a position.
A position out-of-bounds will return either the
first (underflow) or last (overflow) element.

param: int     $pos    0-based index
return: array reference  pseudo-element
author: Tom N Harris <tnharris@whoopdedo.org>

getForm()   X-Ref
Return the assembled HTML for the form.

Each element in the form will be passed to a function named
'form_$type'. The function should return the HTML to be printed.

return: string html of the form
author: Tom N Harris <tnharris@whoopdedo.org>

printForm()   X-Ref
Print the assembled form

wraps around getForm()

addRadioSet($name, $entries)   X-Ref
Add a radio set

This function adds a set of radio buttons to the form. If $_POST[$name]
is set, this radio is preselected, else the first radio button.

param: string    $name    The HTML field name
param: array     $entries An array of entries $value => $caption
author: Adrian Lang <lang@cosmocode.de>

form_makeTag($tag, $attrs = array()   X-Ref
form_makeTag

Create a form element for a non-specific empty tag.

param: string  $tag    Tag name.
param: array   $attrs  Optional attributes.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_makeOpenTag($tag, $attrs = array()   X-Ref
form_makeOpenTag

Create a form element for a non-specific opening tag.
Remember to put a matching close tag after this as well.

param: string  $tag    Tag name.
param: array   $attrs  Optional attributes.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_makeCloseTag($tag)   X-Ref
form_makeCloseTag

Create a form element for a non-specific closing tag.
Careless use of this will result in invalid XHTML.

param: string  $tag    Tag name.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_makeWikiText($text, $attrs = array()   X-Ref
form_makeWikiText

Create a form element for a textarea containing wiki text.
Only one wikitext element is allowed on a page. It will have
a name of 'wikitext' and id 'wiki__text'. The text will
be passed to formText() before printing.

param: string  $text   Text to fill the field with.
param: array   $attrs  Optional attributes.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_makeButton($type, $act, $value = '', $attrs = array()   X-Ref
form_makeButton

Create a form element for an action button.
A title will automatically be generated using the value and
accesskey attributes, unless you provide one.

param: string  $type   Type attribute. 'submit' or 'cancel'
param: string  $act    Wiki action of the button, will be used as the do= parameter
param: string  $value  (optional) Displayed label. Uses $act if not provided.
param: array   $attrs  Optional attributes.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_makeField($type, $name, $value = '', $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeField

Create a form element for a labelled input element.
The label text will be printed before the input.

param: string  $type   Type attribute of input.
param: string  $name   Name attribute of the input.
param: string  $value  (optional) Default value.
param: string  $class  Class attribute of the label. If this is 'block',
param: string  $label  Label that will be printed before the input.
param: string  $id     ID attribute of the input. If set, the label will
param: array   $attrs  Optional attributes.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_makeFieldRight($type, $name, $value = '', $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeFieldRight

Create a form element for a labelled input element.
The label text will be printed after the input.

param: string $type
param: string $name
param: string $value
param: null|string $label
param: string $id
param: string $class
param: array $attrs
return: array
author: Tom N Harris <tnharris@whoopdedo.org>
see: form_makeField

form_makeTextField($name, $value = '', $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeTextField

Create a form element for a text input element with label.

param: string $name
param: string $value
param: null|string $label
param: string $id
param: string $class
param: array $attrs
return: array
author: Tom N Harris <tnharris@whoopdedo.org>
see: form_makeField

form_makePasswordField($name, $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makePasswordField

Create a form element for a password input element with label.
Password elements have no default value, for obvious reasons.

param: string $name
param: null|string $label
param: string $id
param: string $class
param: array $attrs
return: array
author: Tom N Harris <tnharris@whoopdedo.org>
see: form_makeField

form_makeFileField($name, $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeFileField

Create a form element for a file input element with label

param: string $name
param: null|string $label
param: string $id
param: string $class
param: array $attrs
return: array
author: Michael Klier <chi@chimeric.de>
see: form_makeField

form_makeCheckboxField($name, $value = '1', $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeCheckboxField

Create a form element for a checkbox input element with label.
If $value is an array, a hidden field with the same name and the value
$value[1] is constructed as well.

param: string $name
param: string $value
param: null|string $label
param: string $id
param: string $class
param: array $attrs
return: array
author: Tom N Harris <tnharris@whoopdedo.org>
see: form_makeFieldRight

form_makeRadioField($name, $value = '1', $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeRadioField

Create a form element for a radio button input element with label.

param: string $name
param: string $value
param: null|string $label
param: string $id
param: string $class
param: array $attrs
return: array
author: Tom N Harris <tnharris@whoopdedo.org>
see: form_makeFieldRight

form_makeMenuField($name, $values, $selected = '', $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeMenuField

Create a form element for a drop-down menu with label.
The list of values can be strings, arrays of (value,text),
or an associative array with the values as keys and labels as values.
An item is selected by supplying its value or integer index.
If the list of values is an associative array, the selected item must be
a string.

param: string           $name     Name attribute of the input.
param: string[]|array[] $values   The list of values can be strings, arrays of (value,text),
param: string|int       $selected default selected value, string or index number
param: string           $class    Class attribute of the label. If this is 'block',
param: string           $label    Label that will be printed before the input.
param: string           $id       ID attribute of the input. If set, the label will
param: array            $attrs    Optional attributes.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_makeListboxField($name, $values, $selected = '', $label = null, $id = '', $class = '', $attrs = array()   X-Ref
form_makeListboxField

Create a form element for a list box with label.
The list of values can be strings, arrays of (value,text),
or an associative array with the values as keys and labels as values.
Items are selected by supplying its value or an array of values.

param: string           $name     Name attribute of the input.
param: string[]|array[] $values   The list of values can be strings, arrays of (value,text),
param: array|string     $selected value or array of values of the items that need to be selected
param: string           $class    Class attribute of the label. If this is 'block',
param: string           $label    Label that will be printed before the input.
param: string           $id       ID attribute of the input. If set, the label will
param: array            $attrs    Optional attributes.
return: array   pseudo-tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_tag($attrs)   X-Ref
form_tag

Print the HTML for a generic empty tag.
Requires '_tag' key with name of the tag.
Attributes are passed to buildAttributes()

param: array $attrs attributes
return: string html of tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_opentag($attrs)   X-Ref
form_opentag

Print the HTML for a generic opening tag.
Requires '_tag' key with name of the tag.
Attributes are passed to buildAttributes()

param: array $attrs attributes
return: string html of tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_closetag($attrs)   X-Ref
form_closetag

Print the HTML for a generic closing tag.
Requires '_tag' key with name of the tag.
There are no attributes.

param: array $attrs attributes
return: string html of tag
author: Tom N Harris <tnharris@whoopdedo.org>

form_openfieldset($attrs)   X-Ref
form_openfieldset

Print the HTML for an opening fieldset tag.
Uses the '_legend' key.
Attributes are passed to buildAttributes()

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_closefieldset()   X-Ref
form_closefieldset

Print the HTML for a closing fieldset tag.
There are no attributes.

return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_hidden($attrs)   X-Ref
form_hidden

Print the HTML for a hidden input element.
Uses only 'name' and 'value' attributes.
Value is passed to formText()

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_wikitext($attrs)   X-Ref
form_wikitext

Print the HTML for the wiki textarea.
Requires '_text' with default text of the field.
Text will be passed to formText(), attributes to buildAttributes()

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_button($attrs)   X-Ref
form_button

Print the HTML for a form button.
If '_action' is set, the button name will be "do[_action]".
Other attributes are passed to buildAttributes()

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_field($attrs)   X-Ref
form_field

Print the HTML for a form input field.
_class : class attribute used on the label tag
_text  : Text to display before the input. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_fieldright($attrs)   X-Ref
form_fieldright

Print the HTML for a form input field. (right-aligned)
_class : class attribute used on the label tag
_text  : Text to display after the input. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_textfield($attrs)   X-Ref
form_textfield

Print the HTML for a text input field.
_class : class attribute used on the label tag
_text  : Text to display before the input. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_passwordfield($attrs)   X-Ref
form_passwordfield

Print the HTML for a password input field.
_class : class attribute used on the label tag
_text  : Text to display before the input. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_filefield($attrs)   X-Ref
form_filefield

Print the HTML for a file input field.
_class     : class attribute used on the label tag
_text      : Text to display before the input. Not escaped
_maxlength : Allowed size in byte
_accept    : Accepted mime-type
Other attributes are passed to buildAttributes() for the input tag

param: array $attrs attributes
return: string html
author: Michael Klier <chi@chimeric.de>

form_checkboxfield($attrs)   X-Ref
form_checkboxfield

Print the HTML for a checkbox input field.
_class : class attribute used on the label tag
_text  : Text to display after the input. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.
If value is an array, a hidden field with the same name and the value
$attrs['value'][1] is constructed as well.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_radiofield($attrs)   X-Ref
form_radiofield

Print the HTML for a radio button input field.
_class : class attribute used on the label tag
_text  : Text to display after the input. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_menufield($attrs)   X-Ref
form_menufield

Print the HTML for a drop-down menu.
_options : Array of (value,text,selected) for the menu.
Text can be omitted. Text and value are passed to formText()
Only one item can be selected.
_class : class attribute used on the label tag
_text  : Text to display before the menu. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>

form_listboxfield($attrs)   X-Ref
form_listboxfield

Print the HTML for a list box.
_options : Array of (value,text,selected) for the list.
Text can be omitted. Text and value are passed to formText()
_class : class attribute used on the label tag
_text  : Text to display before the menu. Not escaped.
Other attributes are passed to buildAttributes() for the input tag.

param: array $attrs attributes
return: string html
author: Tom N Harris <tnharris@whoopdedo.org>