HTML_QuickForm2
[ class tree: HTML_QuickForm2 ] [ index: HTML_QuickForm2 ] [ all elements ]

Class: HTML_QuickForm2_Rule

Source Location: /HTML_QuickForm2-2.1.0/HTML/QuickForm2/Rule.php

Class Overview


Abstract base class for HTML_QuickForm2 rules


Author(s):

Version:

  • Release: 2.1.0

Variables

Methods


Child classes:

HTML_QuickForm2_Rule_Nonempty
Rule checking that the field is not empty
HTML_QuickForm2_Rule_Compare
Rule comparing the value of the field with some other value
HTML_QuickForm2_Rule_MaxFileSize
Rule checking that uploaded file size does not exceed the given limit
HTML_QuickForm2_Rule_Regex
Validates values using regular expressions
HTML_QuickForm2_Rule_Length
Rule checking the value's length
HTML_QuickForm2_Rule_Email
Validates email address
HTML_QuickForm2_Rule_Callback
Rule checking the value via a callback function (method)
HTML_QuickForm2_Rule_MimeType
Rule checking that uploaded file is of the correct MIME type
HTML_QuickForm2_Rule_Each
Validates all elements in a Container using a template Rule
HTML_QuickForm2_Rule_Empty
Rule checking that the field is empty

Inherited Variables

Inherited Methods


Class Details

[line 36]
Abstract base class for HTML_QuickForm2 rules

This class provides methods that allow chaining several rules together. Its validate() method executes the whole rule chain starting from this rule.



[ Top ]


Class Variables

$chainedRules = array(array())

[line 95]

Rules chained to this one via "and" and "or" operators

The contents can be described as "disjunctive normal form", where an outer array represents a disjunction of conjunctive clauses represented by inner arrays.

  • Access: protected

Type:   array


[ Top ]

$config =

[line 84]

Configuration data for the rule
  • Access: protected

Type:   mixed


[ Top ]

$message =

[line 78]

An error message to display if validation fails
  • Access: protected

Type:   string


[ Top ]

$owner =

[line 72]

An element whose value will be validated by this rule
  • Access: protected



[ Top ]



Method Detail

__construct (Constructor)   [line 105]

HTML_QuickForm2_Rule __construct( HTML_QuickForm2_Node $owner, [string $message = ''], [mixed $config = null])

Class constructor
  • Access: public

Parameters:

HTML_QuickForm2_Node   $owner   —  Element to validate
string   $message   —  Error message to display if validation fails
mixed   $config   —  Configuration data for the rule

[ Top ]

and_   [line 232]

$this and_( HTML_QuickForm2_Rule $next)

Adds a rule to the chain with an "and" operator

Evaluation is short-circuited, next rule will not be evaluated if the previous one returns false. The method is named this way because "and" is a reserved word in PHP.

  • Return: first rule in the chain (i.e. $this)
  • Throws: HTML_QuickForm2_InvalidArgumentException when trying to add a "required" rule to the chain
  • Access: public

Parameters:

HTML_QuickForm2_Rule   $next   — 

[ Top ]

getConfig   [line 148]

mixed getConfig( )

Returns the rule's configuration data
  • Return: Configuration data (specific for a Rule)
  • Access: public

[ Top ]

getJavascript   [line 381]

string getJavascript( [bool $outputTriggers = true])

Returns the client-side representation of the Rule

This creates an instance of either qf.Rule or qf.LiveRule (depends on $outputTriggers) with initialization parameters:

  • callback: {@see getJavascriptCallback()}
  • element ID to set error for if validation fails
  • error message to set if validation fails
  • triggers: {@see getJavascriptTriggers()} (only for qf.LiveRule when $outputTriggers is true)
  • chained rules, array of arrays like in $chainedRules property

  • Throws: HTML_QuickForm2_Exception if Rule or its chained Rules can only be run server-side
  • Access: public

Parameters:

bool   $outputTriggers   —  Whether the Rule will be run onblur / onchange

[ Top ]

getJavascriptCallback   [line 321]

string getJavascriptCallback( )

Returns the client-side validation callback

This essentially builds a Javascript version of validateOwner() method, with element ID and Rule configuration hardcoded.

  • Return: Javascript function to validate the element's value
  • Throws: HTML_QuickForm2_Exception if Rule can only be run server-side
  • Access: protected

Overridden in child classes as:

HTML_QuickForm2_Rule_Nonempty::getJavascriptCallback()
HTML_QuickForm2_Rule_Compare::getJavascriptCallback()
HTML_QuickForm2_Rule_Regex::getJavascriptCallback()
Returns the client-side validation callback
HTML_QuickForm2_Rule_NotRegex::getJavascriptCallback()
Returns the client-side validation callback
HTML_QuickForm2_Rule_Length::getJavascriptCallback()
HTML_QuickForm2_Rule_Email::getJavascriptCallback()
Returns the client-side validation callback
HTML_QuickForm2_Rule_Callback::getJavascriptCallback()
HTML_QuickForm2_Rule_NotCallback::getJavascriptCallback()
HTML_QuickForm2_Rule_Each::getJavascriptCallback()
Builds the callbacks for the owner's children using the template Rule
HTML_QuickForm2_Rule_Empty::getJavascriptCallback()

[ Top ]

getJavascriptTriggers   [line 349]

array getJavascriptTriggers( )

Returns IDs of form fields that should trigger "live" Javascript validation

This returns IDs that are linked to the rule itself and its chained rules. Live validation will be be triggered by 'blur' or 'change' event on any of the elements whose IDs are returned by this method.

  • Access: protected

[ Top ]

getMessage   [line 181]

string getMessage( )

Returns the error message output by the rule
  • Return: Error message
  • Access: public

[ Top ]

getOwnJavascriptTriggers   [line 335]

array getOwnJavascriptTriggers( )

Returns IDs of form fields that should trigger "live" Javascript validation

This returns IDs that are linked to the rule itself.

  • Access: protected

Overridden in child classes as:

HTML_QuickForm2_Rule_Compare::getOwnJavascriptTriggers()

[ Top ]

mergeConfig   [line 123]

mixed mergeConfig( mixed $localConfig, mixed $globalConfig)

Merges local configuration with that provided for registerRule()

Default behaviour is for global config to override local one, different Rules may implement more complex merging behaviours.

  • Return: Merged configuration
  • Access: public

Overridden in child classes as:

HTML_QuickForm2_Rule_Compare::mergeConfig()
Merges local configuration with that provided for registerRule()
HTML_QuickForm2_Rule_Length::mergeConfig()
Merges length limits given on rule creation with those given to registerRule()
HTML_QuickForm2_Rule_Callback::mergeConfig()
Merges local configuration with that provided for registerRule()

Parameters:

mixed   $localConfig   —  Local configuration
mixed   $globalConfig   —  Global configuration, usually provided to HTML_QuickForm2_Factory::registerRule()

[ Top ]

or_   [line 256]

$this or_( HTML_QuickForm2_Rule $next)

Adds a rule to the chain with an "or" operator

Evaluation is short-circuited, next rule will not be evaluated if the previous one returns true. The method is named this way because "or" is a reserved word in PHP.

  • Return: first rule in the chain (i.e. $this)
  • Throws: HTML_QuickForm2_InvalidArgumentException when trying to add a "required" rule to the chain
  • Access: public

Overridden in child classes as:

HTML_QuickForm2_Rule_Required::or_()
Disallows adding a rule to the chain with an "or" operator

Parameters:

HTML_QuickForm2_Rule   $next   — 

[ Top ]

setConfig   [line 137]

$this setConfig( mixed $config)

Sets configuration data for the rule
  • Throws: HTML_QuickForm2_InvalidArgumentException in case of invalid configuration data
  • Access: public

Overridden in child classes as:

HTML_QuickForm2_Rule_Nonempty::setConfig()
Sets minimum number of nonempty values
HTML_QuickForm2_Rule_Compare::setConfig()
Sets the comparison operator and operand to compare to
HTML_QuickForm2_Rule_MaxFileSize::setConfig()
Sets maximum allowed file size
HTML_QuickForm2_Rule_Regex::setConfig()
Sets the regular expression to validate with
HTML_QuickForm2_Rule_Length::setConfig()
Sets the allowed length limits
HTML_QuickForm2_Rule_Callback::setConfig()
Sets the callback to use for validation and its additional arguments
HTML_QuickForm2_Rule_MimeType::setConfig()
Sets allowed MIME type(s) for the uploaded file
HTML_QuickForm2_Rule_Each::setConfig()
Sets the template Rule to use for actual validation

Parameters:

mixed   $config   —  Rule configuration data (specific for a Rule)

[ Top ]

setMessage   [line 163]

$this setMessage( string $message)

Sets the error message output by the rule
  • Throws: HTML_QuickForm2_InvalidArgumentException if trying to validate HTML_QuickForm2_Element_InputHidden with a non-empty error message (e.g. not in Rule chain)
  • Access: public

Overridden in child classes as:

HTML_QuickForm2_Rule_Required::setMessage()
Sets the error message output by the rule

Parameters:

string   $message   —  Error message to display if validation fails

[ Top ]

setOwner   [line 196]

void setOwner( HTML_QuickForm2_Node $owner)

Sets the element that will be validated by this rule
  • Throws: HTML_QuickForm2_InvalidArgumentException if trying to set an instance of HTML_QuickForm2_Element_Static as rule owner; if trying to validate HTML_QuickForm2_Element_InputHidden with a non-empty error message (e.g. not in Rule chain)
  • Access: public

Overridden in child classes as:

HTML_QuickForm2_Rule_MaxFileSize::setOwner()
Sets the element that will be validated by this rule
HTML_QuickForm2_Rule_MimeType::setOwner()
Sets the element that will be validated by this rule
HTML_QuickForm2_Rule_Each::setOwner()
Sets the element that will be validated by this rule

Parameters:

HTML_QuickForm2_Node   $owner   —  Element to validate

[ Top ]

setOwnerError   [line 305]

void setOwnerError( )

Sets the error message on the owner element
  • Access: protected

[ Top ]

validate   [line 275]

boolean validate( )

Performs validation

The whole rule chain is executed. Note that the side effect of this method is setting the error message on element if validation fails

  • Return: Whether the element is valid
  • Access: public

[ Top ]

validateOwner   [line 300]

bool validateOwner( )

Validates the owner element
  • Return: Whether owner element is valid according to the rule
  • Abstract:
  • Access: protected

Overridden in child classes as:

HTML_QuickForm2_Rule_Nonempty::validateOwner()
HTML_QuickForm2_Rule_Compare::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_MaxFileSize::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_Regex::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_NotRegex::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_Length::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_Email::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_Callback::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_NotCallback::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_MimeType::validateOwner()
Validates the owner element
HTML_QuickForm2_Rule_Each::validateOwner()
Validates the owner's children using the template Rule
HTML_QuickForm2_Rule_Empty::validateOwner()

[ Top ]


Documentation generated on Wed, 10 Apr 2019 08:56:11 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.