[ 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.

author: Tom N Harris <tnharris@whoopdedo.org>
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

startFieldset($legend)   X-Ref
startFieldset

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

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

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.

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

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.   *

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

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

Inserts a content element at a position.

author: Tom N Harris <tnharris@whoopdedo.org>
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.

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

Replace with NULL to remove an element.

author: Tom N Harris <tnharris@whoopdedo.org>
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.

findElementByType($type)   X-Ref
findElementByType

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

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

findElementById($id)   X-Ref
findElementById

Gets the position of the element with an ID attribute.

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

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

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

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

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.

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

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.

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

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.

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

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

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

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

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.

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

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.

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

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.

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

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.

author: Tom N Harris <tnharris@whoopdedo.org>
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

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.

author: Tom N Harris <tnharris@whoopdedo.org>
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

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.

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

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.

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

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.

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

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

Create a form element for a file input element with label

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

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.

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

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.

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

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.

author: Tom N Harris <tnharris@whoopdedo.org>
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

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.

author: Tom N Harris <tnharris@whoopdedo.org>
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

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()

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

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()

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

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.

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

form_openfieldset($attrs)   X-Ref
form_openfieldset

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

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

form_closefieldset()   X-Ref
form_closefieldset

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

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

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()

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

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()

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

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()

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

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.

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

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.

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

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.

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

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.

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

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

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

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.

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

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.

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

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.

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

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.

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