*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule InArray * * Check whether value is in list * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_InArray extends WBPAT_Forms_Rule { /** * default config values * - list * - exists value must exist in array * * @var array */ protected $config = array( 'list' => array(), 'exists' => 1 ); /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'Value is not allowed.'), ); return true; } /** * method called by patForms or any patForms_Element to validate the * element or the form. * * @param patForms_Element $form object * @return bool true on sucess */ public function applyRule(&$element, $type = PATFORMS_RULE_AFTER_VALIDATION) { $value = $element->getValue(); if (empty($value)) { return true; } $match = in_array($value, $this->config['list']); // inverse if (1 > intval($this->config['exists'])) { $match = !$match; } if ($match) { return true; } $this->addValidationError(1); return false; } }