Moodle  2.2.1
http://www.collinsharper.com
HTML_QuickForm_RuleRegistry Class Reference

Public Member Functions

 registerRule ($ruleName, $type, $data1, $data2=null)
getRule ($ruleName)
 validate ($ruleName, $values, $options=null, $multiple=false)
 getValidationScript (&$element, $elementName, $ruleData)
 _getJsValue (&$element, $elementName, $reset=false, $index=null)

Static Public Member Functions

singleton ()

Data Fields

 $_rules = array()

Detailed Description

Registers rule objects and uses them for validation

Definition at line 27 of file RuleRegistry.php.


Member Function Documentation

_getJsValue ( &$  element,
elementName,
reset = false,
index = null 
)

Returns JavaScript to get and to reset the element's value

private

Parameters:
objectHTML_QuickForm_element element being processed
stringelement's name
boolwhether to generate JavaScript to reset the value
integervalue's index in the array (only used for multielement rules)
Returns:
array first item is value javascript, second is reset

Definition at line 213 of file RuleRegistry.php.

Here is the caller graph for this function:

& getRule ( ruleName)

Returns a reference to the requested rule object

Parameters:
string$ruleNameName of the requested rule public
Returns:
object

Definition at line 110 of file RuleRegistry.php.

Here is the caller graph for this function:

getValidationScript ( &$  element,
elementName,
ruleData 
)

Returns the validation test in javascript code

Parameters:
mixedElement(s) the rule applies to
stringElement name, in case $element is not array
arrayRule data public
Returns:
string JavaScript for the rule

Definition at line 161 of file RuleRegistry.php.

Here is the call graph for this function:

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

Registers a new validation rule

In order to use a custom rule in your form, you need to register it first. For regular expressions, one can directly use the 'regex' type rule in addRule(), this is faster than registering the rule.

Functions and methods can be registered. Use the 'function' type. When registering a method, specify the class name as second parameter.

You can also register an HTML_QuickForm_Rule subclass with its own validate() method.

Parameters:
string$ruleNameName of validation rule
string$typeEither: 'regex', 'function' or null
string$data1Name of function, regular expression or HTML_QuickForm_Rule object class name
string$data2Object parent of above function or HTML_QuickForm_Rule file path public
Returns:
void

Definition at line 77 of file RuleRegistry.php.

Here is the call graph for this function:

& singleton ( ) [static]

Returns a singleton of HTML_QuickForm_RuleRegistry

Usually, only one RuleRegistry object is needed, this is the reason why it is recommended to use this method to get the validation object.

public

Returns:
object Reference to the HTML_QuickForm_RuleRegistry singleton

Definition at line 47 of file RuleRegistry.php.

Here is the caller graph for this function:

validate ( ruleName,
values,
options = null,
multiple = false 
)

Performs validation on the given values

Parameters:
string$ruleNameName of the rule to be used
mixed$valuesCan be a scalar or an array of values to be validated
mixed$optionsOptions used by the rule
mixed$multipleWhether to validate an array of values altogether public
Returns:
mixed true if no error found, int of valid values (when an array of values is given) or false if error

Definition at line 135 of file RuleRegistry.php.

Here is the call graph for this function:


Field Documentation

$_rules = array()

Definition at line 34 of file RuleRegistry.php.


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