Moodle  2.2.1
http://www.collinsharper.com
HTML_QuickForm Class Reference
Inheritance diagram for HTML_QuickForm:
Collaboration diagram for HTML_QuickForm:

Public Member Functions

 HTML_QuickForm ($formName='', $method='post', $action='', $target='', $attributes=null, $trackSubmit=false)
 apiVersion ()
 registerElementType ($typeName, $include, $className)
 registerRule ($ruleName, $type, $data1, $data2=null)
 elementExists ($element=null)
 setDatasource (&$datasource, $defaultsFilter=null, $constantsFilter=null)
 setDefaults ($defaultValues=null, $filter=null)
 setConstants ($constantValues=null, $filter=null)
 setMaxFileSize ($bytes=0)
 getMaxFileSize ()
createElement ($elementType)
_loadElement ($event, $type, $args)
addElement ($element)
insertElementBefore (&$element, $nameAfter)
addGroup ($elements, $name=null, $groupLabel='', $separator=null, $appendName=true)
getElement ($element)
getElementValue ($element)
 getSubmitValue ($elementName)
 _reindexFiles ($value, $key)
 getElementError ($element)
 setElementError ($element, $message=null)
 getElementType ($element)
 updateElementAttr ($elements, $attrs)
removeElement ($elementName, $removeRules=true)
 addRule ($element, $message, $type, $format=null, $validation='server', $reset=false, $force=false)
 addGroupRule ($group, $arg1, $type='', $format=null, $howmany=0, $validation= 'server', $reset=false)
 addFormRule ($rule)
 applyFilter ($element, $filter)
 _recursiveFilter ($filter, $value)
 arrayMerge ($a, $b)
 isTypeRegistered ($type)
 getRegisteredTypes ()
 isRuleRegistered ($name, $autoRegister=false)
 getRegisteredRules ()
 isElementRequired ($element)
 isElementFrozen ($element)
 setJsWarnings ($pref, $post)
 setRequiredNote ($note)
 getRequiredNote ()
 validate ()
 freeze ($elementList=null)
 isFrozen ()
 process ($callback, $mergeFiles=true)
 accept (&$renderer)
defaultRenderer ()
 toHtml ($in_data=null)
 getValidationScript ()
 getSubmitValues ($mergeFiles=false)
 toArray ($collectHidden=false)
 exportValue ($element)
 exportValues ($elementList=null)
 isSubmitted ()
 isError ($value)
 errorMessage ($value)

Data Fields

 $_elements = array()
 $_elementIndex = array()
 $_duplicateIndex = array()
 $_required = array()
 $_jsPrefix = 'Invalid information entered.'
 $_jsPostfix = 'Please correct these fields.'
 $_datasource
 $_defaultValues = array()
 $_constantValues = array()
 $_submitValues = array()
 $_submitFiles = array()
 $_maxFileSize = 1048576
 $_freezeAll = false
 $_rules = array()
 $_formRules = array()
 $_errors = array()
 $_requiredNote = '<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;"> denotes required field</span>'
 $_flagSubmitted = false

Detailed Description

Create, validate and process HTML forms

Author:
Adam Daniel <adaniel1@eesus.jnj.com>
Bertrand Mansion <bmansion@mamasam.com>
Version:
2.0
Since:
PHP 4.0.3pl1

Definition at line 97 of file QuickForm.php.


Member Function Documentation

& _loadElement ( event,
type,
args 
)

Returns a form element of the given type

Parameters:
string$eventevent to send to newly created element ('createElement' or 'addElement')
string$typeelement type
array$argsarguments for event
Since:
2.0 private
Returns:
object a new element
Exceptions:
HTML_QuickForm_Error

Definition at line 556 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_recursiveFilter ( filter,
value 
)

Recursively apply a filter function

Parameters:
string$filterfilter to apply
mixed$valuesubmitted values
Since:
2.0 private
Returns:
cleaned values

Definition at line 1233 of file QuickForm.php.

Here is the caller graph for this function:

_reindexFiles ( value,
key 
)

A helper function to change the indexes in $_FILES array

Parameters:
mixedSome value from the $_FILES array
stringThe key from the $_FILES array that should be appended
Returns:
array

Definition at line 862 of file QuickForm.php.

Here is the caller graph for this function:

accept ( &$  renderer)

Accepts a renderer

Parameters:
objectAn HTML_QuickForm_Renderer object
Since:
3.0 public
Returns:
void

Reimplemented in MoodleQuickForm.

Definition at line 1619 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

& addElement ( element)

Adds an element into the form

If $element is a string representing element type, then this method accepts variable number of parameters, their meaning and count depending on $element

Parameters:
mixed$elementelement object or type of element to add (text, textarea, file...)
Since:
1.0
Returns:
object reference to element public
Exceptions:
HTML_QuickForm_Error

Definition at line 595 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

addFormRule ( rule)

Adds a global validation rule

This should be used when for a rule involving several fields or if you want to use some completely custom validation for your form. The rule function/method should return true in case of successful validation and array('element name' => 'error') when there were errors.

public

Parameters:
mixedCallback, either function name or array(&$object, 'method')
Exceptions:
HTML_QuickForm_Error

Definition at line 1177 of file QuickForm.php.

Here is the call graph for this function:

& addGroup ( elements,
name = null,
groupLabel = '',
separator = null,
appendName = true 
)

Adds an element group

Parameters:
array$elementsarray of elements composing the group
string$name(optional)group name
string$groupLabel(optional)group label
string$separator(optional)string to separate elements
string$appendName(optional)specify whether the group name should be used in the form element name ex: group[element]
Returns:
object reference to added group of elements
Since:
2.8 public
Exceptions:
PEAR_Error

Definition at line 717 of file QuickForm.php.

Here is the call graph for this function:

addGroupRule ( group,
arg1,
type = '',
format = null,
howmany = 0,
validation = 'server',
reset = false 
)

Adds a validation rule for the given group of elements

Only groups with a name can be assigned a validation rule Use addGroupRule when you need to validate elements inside the group. Use addRule if you need to validate the group as a whole. In this case, the same rule will be applied to all elements in the group. Use addRule if you need to validate the group against a function.

Parameters:
string$groupForm group name
mixed$arg1Array for multiple elements or error message string for one element
string$type(optional)Rule type use getRegisteredRules() to get types
string$format(optional)Required for extra rule data
int$howmany(optional)How many valid elements should be in the group
string$validation(optional)Where to perform validation: "server", "client"
bool$resetClient-side: whether to reset the element's value to its original state if validation failed.
Since:
2.5 public
Exceptions:
HTML_QuickForm_Error

Reimplemented in MoodleQuickForm.

Definition at line 1087 of file QuickForm.php.

Here is the call graph for this function:

addRule ( element,
message,
type,
format = null,
validation = 'server',
reset = false,
force = false 
)

Adds a validation rule for the given field

If the element is in fact a group, it will be considered as a whole. To validate grouped elements as separated entities, use addGroupRule instead of addRule.

Parameters:
string$elementForm element name
string$messageMessage to display for invalid data
string$typeRule type, use getRegisteredRules() to get types
string$format(optional)Required for extra rule data
string$validation(optional)Where to perform validation: "server", "client"
boolean$resetClient-side validation: reset the form element to its original value if there is an error?
boolean$forceForce the rule to be applied, even if the target form element does not exist
Since:
1.0 public
Exceptions:
HTML_QuickForm_Error

Reimplemented in MoodleQuickForm.

Definition at line 1021 of file QuickForm.php.

Here is the call graph for this function:

Returns the current API version

Since:
1.0 public
Returns:
float

Reimplemented from HTML_Common.

Definition at line 314 of file QuickForm.php.

applyFilter ( element,
filter 
)

Applies a data filter for the given field(s)

Parameters:
mixed$elementForm element name or array of such names
mixed$filterCallback, either function name or array(&$object, 'method')
Since:
2.0 public

Definition at line 1196 of file QuickForm.php.

Here is the call graph for this function:

arrayMerge ( a,
b 
)

Merges two arrays

Merges two array like the PHP function array_merge but recursively. The main difference is that existing keys will not be renumbered if they are integers.

puplic

Parameters:
array$aoriginal array
array$barray which will be merged into first one
Returns:
array merged array

Definition at line 1261 of file QuickForm.php.

Here is the caller graph for this function:

& createElement ( elementType)

Creates a new form element of the given type.

This method accepts variable number of parameters, their meaning and count depending on $elementType

Parameters:
string$elementTypetype of element to add (text, textarea, file...)
Since:
1.0 public
Returns:
object extended class of HTML_element
Exceptions:
HTML_QuickForm_Error

Definition at line 535 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a reference to default renderer object

public

Since:
3.0
Returns:
object a default renderer object

Definition at line 1642 of file QuickForm.php.

Here is the caller graph for this function:

elementExists ( element = null)

Returns true if element is in the form

Parameters:
string$elementform name of element to check
Since:
1.0 public
Returns:
boolean

Definition at line 369 of file QuickForm.php.

Here is the caller graph for this function:

errorMessage ( value)

Return a textual error message for an QuickForm error code

public

Parameters:
interror code
Returns:
string error message

Definition at line 1926 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

exportValue ( element)

Returns a 'safe' element's value

This method first tries to find a cleaned-up submitted value, it will return a value set by setValue()/setDefaults()/setConstants() if submitted value does not exist for the given element.

Parameters:
stringName of an element public
Returns:
mixed

Definition at line 1822 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

exportValues ( elementList = null)

Returns 'safe' elements' values

Unlike getSubmitValues(), this will return only the values corresponding to the elements present in the form.

Parameters:
mixedArray/string of element names, whose values we want. If not set then return all elements. public
Returns:
array An assoc array of elements' values
Exceptions:
HTML_QuickForm_Error

Reimplemented in MoodleQuickForm.

Definition at line 1856 of file QuickForm.php.

Here is the call graph for this function:

freeze ( elementList = null)

Displays elements without HTML input tags

Parameters:
mixed$elementListarray or string of element(s) to be frozen
Since:
1.0 public
Exceptions:
HTML_QuickForm_Error

Definition at line 1546 of file QuickForm.php.

Here is the call graph for this function:

& getElement ( element)

Returns a reference to the element

Parameters:
string$elementElement name
Since:
2.0 public
Returns:
object reference to element
Exceptions:
HTML_QuickForm_Error

Definition at line 741 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getElementError ( element)

Returns error corresponding to validated element

Parameters:
string$elementName of form element to check
Since:
1.0 public
Returns:
string error message corresponding to checked element

Definition at line 886 of file QuickForm.php.

Here is the caller graph for this function:

getElementType ( element)

Returns the type of the given element

Parameters:
string$elementName of form element
Since:
1.1 public
Returns:
string Type of the element, false if the element is not found

Definition at line 925 of file QuickForm.php.

Here is the caller graph for this function:

& getElementValue ( element)

Returns the element's raw value

This returns the value as submitted by the form (not filtered) or set via setDefaults() or setConstants()

Parameters:
string$elementElement name
Since:
2.0 public
Returns:
mixed element value
Exceptions:
HTML_QuickForm_Error

Definition at line 766 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the value of MAX_FILE_SIZE hidden element

Since:
3.0 public
Returns:
int max file size in bytes

Definition at line 515 of file QuickForm.php.

Returns an array of registered validation rules

Since:
1.0 public
Returns:
array

Definition at line 1361 of file QuickForm.php.

Returns an array of registered element types

Since:
1.0 public
Returns:
array

Definition at line 1306 of file QuickForm.php.

Returns the required note

Since:
2.0 public
Returns:
string

Definition at line 1445 of file QuickForm.php.

getSubmitValue ( elementName)

Returns the elements value after submit and filter

Parameters:
stringElement name
Since:
2.0 public
Returns:
mixed submitted element value or null if not set

Definition at line 798 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getSubmitValues ( mergeFiles = false)

Returns the values submitted by the form

Since:
2.0 public
Parameters:
boolWhether uploaded files should be returned too
Returns:
array

Definition at line 1782 of file QuickForm.php.

Here is the call graph for this function:

Returns the client side validation script

Since:
2.0 public
Returns:
string Javascript to perform validation, empty string if no 'client' rules were added

Reimplemented in MoodleQuickForm, and HTML_QuickForm_DHTMLRulesTableless.

Definition at line 1684 of file QuickForm.php.

Here is the call graph for this function:

HTML_QuickForm ( formName = '',
method = 'post',
action = '',
target = '',
attributes = null,
trackSubmit = false 
)

Class constructor

Parameters:
string$formNameForm's name.
string$method(optional)Form's method defaults to 'POST'
string$action(optional)Form's action
string$target(optional)Form's target defaults to '_self'
mixed$attributes(optional)Extra attributes for <form> tag
bool$trackSubmit(optional)Whether to track if the form was submitted by adding a special hidden field public

Definition at line 256 of file QuickForm.php.

Here is the call graph for this function:

& insertElementBefore ( &$  element,
nameAfter 
)

Inserts a new element right before the other element

Warning: it is not possible to check whether the $element is already added to the form, therefore if you want to move the existing form element to a new position, you'll have to use removeElement(): $form->insertElementBefore($form->removeElement('foo', false), 'bar');

public

Since:
3.2.4
Parameters:
objectHTML_QuickForm_element Element to insert
stringName of the element before which the new one is inserted
Returns:
object HTML_QuickForm_element reference to inserted element
Exceptions:
HTML_QuickForm_Error

Definition at line 650 of file QuickForm.php.

Here is the call graph for this function:

isElementFrozen ( element)

Returns whether or not the form element is frozen

Parameters:
string$elementForm element name
Since:
1.0 public
Returns:
boolean

Definition at line 1393 of file QuickForm.php.

isElementRequired ( element)

Returns whether or not the form element is required

Parameters:
string$elementForm element name
Since:
1.0 public
Returns:
boolean

Definition at line 1377 of file QuickForm.php.

Here is the caller graph for this function:

isError ( value)

Tell whether a result from a QuickForm method is an error (an instance of HTML_QuickForm_Error)

public

Parameters:
mixedresult code
Returns:
bool whether $value is an error

Definition at line 1911 of file QuickForm.php.

Here is the caller graph for this function:

isFrozen ( )

Returns whether or not the whole form is frozen

Since:
3.0 public
Returns:
boolean

Definition at line 1582 of file QuickForm.php.

Here is the caller graph for this function:

isRuleRegistered ( name,
autoRegister = false 
)

Returns whether or not the given rule is supported

Parameters:
string$nameValidation rule name
boolWhether to automatically register subclasses of HTML_QuickForm_Rule
Since:
1.0 public
Returns:
mixed true if previously registered, false if not, new rule name if auto-registering worked

Definition at line 1323 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Tells whether the form was already submitted

This is useful since the _submitFiles and _submitValues arrays may be completely empty after the trackSubmit value is removed.

public

Returns:
bool

Reimplemented in MoodleQuickForm.

Definition at line 1895 of file QuickForm.php.

Here is the caller graph for this function:

isTypeRegistered ( type)

Returns whether or not the form element type is supported

Parameters:
string$typeForm element type
Since:
1.0 public
Returns:
boolean

Definition at line 1291 of file QuickForm.php.

Here is the caller graph for this function:

process ( callback,
mergeFiles = true 
)

Performs the form data processing

Parameters:
mixed$callbackCallback, either function name or array(&$object, 'method')
bool$mergeFilesWhether uploaded files should be processed too
Since:
1.0 public
Exceptions:
HTML_QuickForm_Error

Definition at line 1599 of file QuickForm.php.

Here is the call graph for this function:

registerElementType ( typeName,
include,
className 
)

Registers a new element type

Parameters:
string$typeNameName of element type
string$includeInclude path for element type
string$classNameElement class name
Since:
1.0 public
Returns:
void

Definition at line 332 of file QuickForm.php.

registerRule ( ruleName,
type,
data1,
data2 = null 
)

Registers a new validation rule

Parameters:
string$ruleNameName of validation rule
string$typeEither: 'regex', 'function' or 'rule' for an HTML_QuickForm_Rule object
string$data1Name of function, regular expression or HTML_QuickForm_Rule classname
string$data2Object parent of above function or HTML_QuickForm_Rule file path
Since:
1.0 public
Returns:
void

Definition at line 351 of file QuickForm.php.

Here is the call graph for this function:

& removeElement ( elementName,
removeRules = true 
)

Removes an element

The method "unlinks" an element from the form, returning the reference to the element object. If several elements named $elementName exist, it removes the first one, leaving the others intact.

Parameters:
string$elementNameThe element name
boolean$removeRulesTrue if rules for this element are to be removed too public
Since:
2.0
Returns:
object HTML_QuickForm_element a reference to the removed element
Exceptions:
HTML_QuickForm_Error

Definition at line 981 of file QuickForm.php.

Here is the call graph for this function:

setConstants ( constantValues = null,
filter = null 
)

Initializes constant form values. These values won't get overridden by POST or GET vars

Parameters:
array$constantValuesvalues used to fill the form
mixed$filter(optional) filter(s) to apply to all default values
Since:
2.0 public
Returns:
void

Definition at line 456 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

setDatasource ( &$  datasource,
defaultsFilter = null,
constantsFilter = null 
)

Sets a datasource object for this form object

Datasource default and constant values will feed the QuickForm object if the datasource implements defaultValues() and constantValues() methods.

Parameters:
object$datasourcedatasource object implementing the informal datasource protocol
mixed$defaultsFilterstring or array of filter(s) to apply to default values
mixed$constantsFilterstring or array of filter(s) to apply to constants values
Since:
3.3 public
Returns:
void

Definition at line 390 of file QuickForm.php.

Here is the call graph for this function:

setDefaults ( defaultValues = null,
filter = null 
)

Initializes default form values

Parameters:
array$defaultValuesvalues used to fill the form
mixed$filter(optional) filter(s) to apply to all default values
Since:
1.0 public
Returns:
void

Definition at line 417 of file QuickForm.php.

Here is the call graph for this function:

Here is the caller graph for this function:

setElementError ( element,
message = null 
)

Set error message for a form element

Parameters:
string$elementName of form element to set error for
string$messageError message, if empty then removes the current error message
Since:
1.0 public
Returns:
void

Definition at line 905 of file QuickForm.php.

setJsWarnings ( pref,
post 
)

Sets JavaScript warning messages

Parameters:
string$prefPrefix warning
string$postPostfix warning
Since:
1.1 public
Returns:
void

Definition at line 1413 of file QuickForm.php.

setMaxFileSize ( bytes = 0)

Sets the value of MAX_FILE_SIZE hidden element

Parameters:
int$bytesSize in bytes
Since:
3.0 public
Returns:
void

Definition at line 492 of file QuickForm.php.

Here is the call graph for this function:

setRequiredNote ( note)

Sets required-note

Parameters:
string$noteMessage indicating some elements are required
Since:
1.1 public
Returns:
void

Definition at line 1430 of file QuickForm.php.

toArray ( collectHidden = false)

Returns the form's contents in an array.

The description of the array structure is in HTML_QuickForm_Renderer_Array docs

Since:
2.0 public
Parameters:
boolWhether to collect hidden elements (passed to the Renderer's constructor)
Returns:
array of form contents

Definition at line 1800 of file QuickForm.php.

Here is the call graph for this function:

toHtml ( in_data = null)

Returns an HTML version of the form

Parameters:
string$in_data(optional) Any extra data to insert right before form is rendered. Useful when using templates.
Returns:
string Html version of the form
Since:
1.0 public

Definition at line 1664 of file QuickForm.php.

Here is the call graph for this function:

updateElementAttr ( elements,
attrs 
)

Updates Attributes for one or more elements

Parameters:
mixed$elementsArray of element names/objects or string of elements to be updated
mixed$attrsArray or sting of html attributes
Since:
2.10 public
Returns:
void

Definition at line 945 of file QuickForm.php.

validate ( )

Performs the server side validation public

Since:
1.0
Returns:
boolean true if no error found

Definition at line 1459 of file QuickForm.php.

Here is the call graph for this function:


Field Documentation

$_constantValues = array()

Definition at line 171 of file QuickForm.php.

$_datasource

Definition at line 155 of file QuickForm.php.

$_defaultValues = array()

Definition at line 163 of file QuickForm.php.

$_duplicateIndex = array()

Definition at line 122 of file QuickForm.php.

$_elementIndex = array()

Definition at line 114 of file QuickForm.php.

$_elements = array()

Definition at line 106 of file QuickForm.php.

$_errors = array()

Definition at line 226 of file QuickForm.php.

$_flagSubmitted = false

Definition at line 241 of file QuickForm.php.

$_formRules = array()

Definition at line 218 of file QuickForm.php.

$_freezeAll = false

Definition at line 203 of file QuickForm.php.

$_jsPostfix = 'Please correct these fields.'

Definition at line 146 of file QuickForm.php.

$_jsPrefix = 'Invalid information entered.'

Definition at line 138 of file QuickForm.php.

$_maxFileSize = 1048576

Definition at line 195 of file QuickForm.php.

$_required = array()

Definition at line 130 of file QuickForm.php.

$_requiredNote = '<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;"> denotes required field</span>'

Definition at line 234 of file QuickForm.php.

$_rules = array()

Definition at line 211 of file QuickForm.php.

$_submitFiles = array()

Definition at line 187 of file QuickForm.php.

$_submitValues = array()

Definition at line 179 of file QuickForm.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations