/functions/forms.php

Description

forms.php - html form functions

Functions to build HTML forms in a safe and consistent manner. All attribute values are sanitized with htmlspecialchars().

Currently functions don't provide simple wrappers for file and image input fields, support only submit and reset buttons and use html input tags for buttons.

Since 1.5.1:

* all form functions should support id tags. Original idea by dugan <at> passwall.com. Tags can be used for Section 508 or WAI compliance.

* input tag functions accept extra html attributes that can be submitted in $aAttribs array.

* default css class attributes are added.

Functions
addCheckBox (line 93)

Form checkbox

  • return: html formated checkbox field
string addCheckBox (string $sName, [boolean $bChecked = false], [string $sValue = null], [array $aAttribs = array()])
  • string $sName: field name
  • boolean $bChecked: controls if field is checked
  • string $sValue
  • array $aAttribs: (since 1.5.1) extra attributes
addForm (line 278)

Make a <form> start-tag.

  • return: html formated form start string
string addForm (string $sAction, [string $sMethod = 'post'], [string $sName = ''], [string $sEnctype = ''], [string $sCharset = ''], [array $aAttribs = array()])
  • string $sAction: form handler URL
  • string $sMethod: http method used to submit form data. 'get' or 'post'
  • string $sName: form name used for identification (used for backward compatibility). Use of id is recommended.
  • string $sEnctype: content type that is used to submit data. html 4.01 defaults to 'application/x-www-form-urlencoded'. Form with file field needs 'multipart/form-data' encoding type.
  • string $sCharset: charset that is used for submitted data
  • array $aAttribs: (since 1.5.1) extra attributes
addHidden (line 127)

A hidden form field.

  • return: formated hidden form field
html addHidden (string $sName, string $sValue, [array $aAttribs = array()])
  • string $sName: field name
  • string $sValue: field value
  • array $aAttribs: (since 1.5.1) extra attributes
addInput (line 145)

An input textbox.

  • return: html formated text input field
string addInput (string $sName, [string $sValue = ''], [integer $iSize = 0], [integer $iMaxlength = 0], [array $aAttribs = array()])
  • string $sName: field name
  • string $sValue: initial field value
  • integer $iSize: field size (number of characters)
  • integer $iMaxlength: maximum number of characters the user may enter
  • array $aAttribs: (since 1.5.1) extra attributes - should be given in the form array('attribute_name' => 'attribute_value', ...)
addInputField (line 49)

Helper function to create form fields, not to be called directly, only by other functions below.

Function used different syntax before 1.5.1

  • return: html formated input field
  • deprecated: use other functions that provide simple wrappers to this function
string addInputField (string $sType, [array $aAttribs = array()])
  • string $sType: type of input field. Possible values (html 4.01 specs.): text, password, checkbox, radio, submit, reset, file, hidden, image, button.
  • array $aAttribs: (since 1.5.1) extra attributes. Array key is attribute name, array value is attribute value. Array keys must use lowercase.
addPwField (line 77)

Password input field

  • return: html formated password field
string addPwField (string $sName, [string $sValue = null], [array $aAttribs = array()])
  • string $sName: field name
  • string $sValue: initial password value
  • array $aAttribs: (since 1.5.1) extra attributes
addRadioBox (line 110)

Form radio box

  • return: html formated radio box
string addRadioBox (string $sName, [boolean $bChecked = false], [string $sValue = null], [array $aAttribs = array()])
  • string $sName: field name
  • boolean $bChecked: controls if field is selected
  • string $sValue
  • array $aAttribs: (since 1.5.1) extra attributes.
addReset (line 221)

Form reset button

  • return: html formated reset input field
string addReset (string $sValue, [array $aAttribs = array()])
  • string $sValue: button name
  • array $aAttribs: (since 1.5.1) extra attributes
addSelect (line 165)

Function to create a selectlist from an array.

  • return: html formated selection box
  • todo: add attributes argument for option tags and default css
string addSelect (string $sName, array $aValues, [mixed $default = null], [boolean $bUsekeys = false], [array $aAttribs = array()])
  • string $sName: field name
  • array $aValues: field values array ( key => value ) -> <option value="key">value</option>
  • mixed $default: the key that will be selected
  • boolean $bUsekeys: use the keys of the array as option value or not
  • array $aAttribs: (since 1.5.1) extra attributes
addSubmit (line 208)

Form submission button

Note the switched value/name parameters!

  • return: html formated submit input field
string addSubmit (string $sValue, [string $sName = null], [array $aAttribs = array()])
  • string $sValue: button name
  • string $sName: submitted key name
  • array $aAttribs: (since 1.5.1) extra attributes
addTextArea (line 238)

Textarea form element.

  • return: html formated text area field
string addTextArea (string $sName, [string $sText = ''], [integer $iCols = 40], [integer $iRows = 10], [array $aAttribs = array()])
  • string $sName: field name
  • string $sText: initial field value
  • integer $iCols: field width (number of chars)
  • integer $iRows: field height (number of character rows)
  • array $aAttribs: (since 1.5.1) extra attributes. function accepts string argument for backward compatibility.

Documentation generated on Sat, 07 Oct 2006 16:11:05 +0300 by phpDocumentor 1.3.0RC6