Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

(no description)

File Size: 334 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

HTML_QuickForm_RuleRegistry:: (6 methods):
  singleton()
  registerRule()
  getRule()
  validate()
  getValidationScript()
  _getJsValue()


Class: HTML_QuickForm_RuleRegistry  - X-Ref

Registers rule objects and uses them for validation

singleton()   X-Ref
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.

return: object    Reference to the HTML_QuickForm_RuleRegistry singleton

registerRule($ruleName, $type, $data1, $data2 = null)   X-Ref
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.

param: string    $ruleName   Name of validation rule
param: string    $type       Either: 'regex', 'function' or null
param: string    $data1      Name of function, regular expression or
param: string    $data2      Object parent of above function or HTML_QuickForm_Rule file path
return: void

getRule($ruleName)   X-Ref
Returns a reference to the requested rule object

param: string   $ruleName        Name of the requested rule
return: object

validate($ruleName, $values, $options = null, $multiple = false)   X-Ref
Performs validation on the given values

param: string   $ruleName        Name of the rule to be used
param: mixed    $values          Can be a scalar or an array of values
param: mixed    $options         Options used by the rule
param: mixed    $multiple        Whether to validate an array of values altogether
return: mixed    true if no error found, int of valid values (when an array of values is given) or false if error

getValidationScript(&$element, $elementName, $ruleData)   X-Ref
Returns the validation test in javascript code

param: mixed     Element(s) the rule applies to
param: string    Element name, in case $element is not array
param: array     Rule data
return: string    JavaScript for the rule

_getJsValue(&$element, $elementName, $reset = false, $index = null)   X-Ref
Returns JavaScript to get and to reset the element's value

param: object HTML_QuickForm_element     element being processed
param: string    element's name
param: bool      whether to generate JavaScript to reset the value
param: integer   value's index in the array (only used for multielement rules)
return: array     first item is value javascript, second is reset