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

Class: HTML_QuickForm2_Rule_Length

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

Class Overview

HTML_QuickForm2_Rule
   |
   --HTML_QuickForm2_Rule_Length

Rule checking the value's length


Author(s):

Version:

  • Release: 2.1.0

Methods


Inherited Variables

Inherited Methods

Class: HTML_QuickForm2_Rule

HTML_QuickForm2_Rule::__construct()
Class constructor
HTML_QuickForm2_Rule::and_()
Adds a rule to the chain with an "and" operator
HTML_QuickForm2_Rule::getConfig()
Returns the rule's configuration data
HTML_QuickForm2_Rule::getJavascript()
Returns the client-side representation of the Rule
HTML_QuickForm2_Rule::getJavascriptCallback()
Returns the client-side validation callback
HTML_QuickForm2_Rule::getJavascriptTriggers()
Returns IDs of form fields that should trigger "live" Javascript validation
HTML_QuickForm2_Rule::getMessage()
Returns the error message output by the rule
HTML_QuickForm2_Rule::getOwnJavascriptTriggers()
Returns IDs of form fields that should trigger "live" Javascript validation
HTML_QuickForm2_Rule::mergeConfig()
Merges local configuration with that provided for registerRule()
HTML_QuickForm2_Rule::or_()
Adds a rule to the chain with an "or" operator
HTML_QuickForm2_Rule::setConfig()
Sets configuration data for the rule
HTML_QuickForm2_Rule::setMessage()
Sets the error message output by the rule
HTML_QuickForm2_Rule::setOwner()
Sets the element that will be validated by this rule
HTML_QuickForm2_Rule::setOwnerError()
Sets the error message on the owner element
HTML_QuickForm2_Rule::validate()
Performs validation
HTML_QuickForm2_Rule::validateOwner()
Validates the owner element

Class Details

[line 56]
Rule checking the value's length

The rule needs an "allowed length" parameter for its work, it can be either

  • a scalar: the value will be valid if it is exactly this long
  • an array: the value will be valid if its length is between the given values (inclusive). If one of these evaluates to 0, then length will be compared only with the remaining one.
See mergeConfig() for description of possible ways to pass configuration parameters.

The Rule considers empty fields as valid and doesn't try to compare their lengths with provided limits.

For convenience this Rule is also registered with the names 'minlength' and 'maxlength' (having, respectively, 'max' and 'min' parameters set to 0):

  1.  $password->addRule('minlength''The password should be at least 6 characters long'6);
  2.  $message->addRule('maxlength''Your message is too verbose'1000);



[ Top ]


Method Detail

getJavascriptCallback   [line 78]

void getJavascriptCallback( )

  • Access: protected

Overrides HTML_QuickForm2_Rule::getJavascriptCallback() (Returns the client-side validation callback)
[ Top ]

mergeConfig   [line 152]

int|array mergeConfig( int|array $localConfig, int|array $globalConfig)

Merges length limits given on rule creation with those given to registerRule()

"Global" length limits may be passed to HTML_QuickForm2_Factory::registerRule() in either of the following formats

  • scalar (exact length)
  • array(minlength, maxlength)
  • array(['min' => minlength, ]['max' => maxlength])
"Local" length limits may be passed to the constructor in either of the following formats
  • scalar (if global config is unset then it is treated as an exact length, if 'min' or 'max' is in global config then it is treated as 'max' or 'min', respectively)
  • array(minlength, maxlength)
  • array(['min' => minlength, ]['max' => maxlength])
As usual, global configuration overrides local one.

  • Return: Merged length limits
  • Access: public

Overrides HTML_QuickForm2_Rule::mergeConfig() (Merges local configuration with that provided for registerRule())

Parameters:

int|array   $localConfig   —  Local length limits
int|array   $globalConfig   —  Global length limits, usually provided to HTML_QuickForm2_Factory::registerRule()

[ Top ]

mergeMinMaxLength   [line 106]

array mergeMinMaxLength( array $length, array $config)

Adds the 'min' and 'max' fields from one array to the other
  • Access: protected

Parameters:

array   $length   —  Rule configuration, array with 'min' and 'max' keys
array   $config   —  Additional configuration, fields will be added to $length if it doesn't contain such a key already

[ Top ]

setConfig   [line 185]

HTML_QuickForm2_Rule setConfig( int|array $config)

Sets the allowed length limits

$config can be either of the following

  • integer (rule checks for exact length)
  • array(minlength, maxlength)
  • array(['min' => minlength, ]['max' => maxlength])

  • Throws: HTML_QuickForm2_InvalidArgumentException if bogus length limits were provided
  • Access: public

Overrides HTML_QuickForm2_Rule::setConfig() (Sets configuration data for the rule)

Parameters:

int|array   $config   —  Length limits

[ Top ]

validateOwner   [line 63]

bool validateOwner( )

Validates the owner element
  • Return: whether length of the element's value is within allowed range
  • Access: protected

Overrides HTML_QuickForm2_Rule::validateOwner() (Validates the owner element)
[ Top ]


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