*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule UrlOrEmail * * String must be an URL or an e-mail address * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_UrlOrEmail extends WBPAT_Forms_Rule { /** * default config values * * @var array */ protected $config = array( ); /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { 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) { $me = $element->getValue(); if (empty($me)) { return true; } // validate e-mail address if (strstr($me, '@')) { return $this->applyRuleEmail($element, $type); } // allow 'www' links without 'http://' if (strncmp($me, 'www.', 4) == 0) { $element->setValue('http://' . $me); } return $this->applyRuleUrl($element, $type); } private function applyRuleEmail($element, $type) { $rule = patForms::createRule('Email'); $rule->prepareRule($element); if ($rule->applyRule($element, $type)) { return true; } return false; } private function applyRuleUrl($element, $type) { $rule = patForms::createRule('URL'); $rule->prepareRule($element); if ($rule->applyRule($element, $type)) { return true; } return false; } } ?>