*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule InOther * * Test whether given value is in other * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_InOther extends WBPAT_Forms_Rule { /** * default config values * - other * - in * * @var array */ protected $config = array( 'other' => null, 'in' => 'yes' ); /** * 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', 'The value must also be in "[TITLE]".'), 2 => patI18n::dgettext('wombat', 'Value was found in "[TITLE]" but not expected.'), ); 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) { if (empty($this->config['other'])) { WBClass::load('WBException_Config'); throw new WBException_Config('Config value "other" must be form element', 1, __CLASS__); } $me = $element->getValue(); if (empty($me)) { return true; } $other = $this->config['other']->getValue(); if (!is_array($other)) { $other = array($other); } $info = array( 'title' => $this->config['other']->getAttribute('title') ); $in = in_array($me, $other); if ($this->config['in'] == 'yes' && !$in) { $this->addValidationError(1, $info); return false; } if ($this->config['in'] != 'yes' && $in) { $this->addValidationError(2, $info); return false; } return true; } } ?>