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

Class: HTML_QuickForm2_Rule_Callback

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

Class Overview

HTML_QuickForm2_Rule
   |
   --HTML_QuickForm2_Rule_Callback

Rule checking the value via a callback function (method)


Author(s):

Version:

  • Release: 2.1.0

Methods


Child classes:

HTML_QuickForm2_Rule_NotCallback
Rule checking the value via a callback function (method) with logical negation

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 66]
Rule checking the value via a callback function (method)

The Rule needs a valid callback as a configuration parameter for its work, it may also be given additional arguments to pass to the callback alongside the element's value. See mergeConfig() for description of possible ways to pass configuration parameters.

The callback will be called with element's value as the first argument, if additional arguments were provided they'll be passed as well. It is expected to return false if the value is invalid and true if it is valid.

Checking that the value is not empty:

  1.  $str->addRule('callback''The field should not be empty''strlen');
Checking that the value is in the given array:
  1.  $meta->addRule('callback''Unknown variable name',
  2.                 array('callback' => 'in_array',
  3.                       'arguments' => array(array('foo''bar''baz'))));
The same, but with rule registering first:
  1.      'in_array''HTML_QuickForm2_Rule_Callback',
  2.      'HTML/QuickForm2/Rule/Callback.php''in_array'
  3.  );
  4.  $meta->addRule('in_array''Unknown variable name'array(array('foo''bar''baz')));



[ Top ]


Method Detail

arrayHasSomeKeys   [line 145]

bool arrayHasSomeKeys( mixed $search, array $keys)

Tests whether a given value is an array containing at least one of the given keys
  • Access: protected

Parameters:

mixed   $search   —  if not an array, method will return false
array   $keys   —  keys to test for

[ Top ]

findJavascriptName   [line 111]

string findJavascriptName( )

Finds a name for Javascript callback function

The method first checks whether javascript callback 'js_callback' was provided to the Rule and returns that if found.

If an explicit 'js_callback' was not provided, it tries to generate a name equal (for a given value of "equal") to PHP callback name. This may be useful if e.g. using HTML_AJAX package to generate class stubs in JS and in similar circumstances.

If a callback does not have a name (it is a lambda function or a closure) then an exception will be raised.

  • Access: protected

[ Top ]

getJavascriptCallback   [line 82]

void getJavascriptCallback( )

  • Access: protected

Overridden in child classes as:

HTML_QuickForm2_Rule_NotCallback::getJavascriptCallback()

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

mergeConfig   [line 180]

mixed mergeConfig( mixed $localConfig, mixed $globalConfig)

Merges local configuration with that provided for registerRule()

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

  • callback
  • array(['callback' => callback][, 'arguments' => array(...)][, 'js_callback' => string])
"Local" configuration may be passed to the constructor in either of the following formats
  • callback or arguments (interpretation depends on whether the global configuration already contains the callback)
  • array(['callback' => callback][, 'arguments' => array(...)][, 'js_callback' => string])
As usual, global config overrides local one. It is a good idea to use the associative array format to prevent ambiguity.

  • Return: Merged configuration
  • Access: public

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

Parameters:

mixed   $localConfig   —  Local configuration
mixed   $globalConfig   —  Global configuration

[ Top ]

setConfig   [line 212]

HTML_QuickForm2_Rule setConfig( callback|array $config)

Sets the callback to use for validation and its additional arguments
  • Throws: HTML_QuickForm2_InvalidArgumentException if callback is missing or invalid or additional arguments is not an array
  • Access: public

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

Parameters:

callback|array   $config   —  Callback or array ('callback' => validation callback [, 'arguments' => additional arguments] [, 'js_callback' => javascript callback for client-side validation])

[ Top ]

validateOwner   [line 73]

bool validateOwner( )

Validates the owner element
  • Return: the value returned by a callback function
  • Access: protected

Overridden in child classes as:

HTML_QuickForm2_Rule_NotCallback::validateOwner()
Validates the owner element

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


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