* @author Adam Daniel * @author Bertrand Mansion * @author Justin Patrin * @author Mark Wiesemann * @copyright 2005-2006 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: DHTMLRulesTableless.php,v 1.2 2006/09/27 16:31:11 jamiesensei Exp $ * @link http://pear.php.net/package/HTML_QuickForm_DHTMLRulesTableless */ require_once 'HTML/QuickForm.php'; /** * This is a DHTML replacement for the standard JavaScript alert window for * client-side validation of forms built with HTML_QuickForm * * @category HTML * @package HTML_QuickForm_DHTMLRulesTableless * @author Alexey Borzov * @author Adam Daniel * @author Bertrand Mansion * @author Justin Patrin * @author Mark Wiesemann * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version Release: 0.1.3 * @link http://pear.php.net/package/HTML_QuickForm_DHTMLRulesTableless */ class HTML_QuickForm_DHTMLRulesTableless extends HTML_QuickForm { // {{{ getValidationScript() /** * Returns the client side validation script * * The code here was copied from HTML_QuickForm and slightly modified to run rules per-element * * @access public * @return string Javascript to perform validation, empty string if no 'client' rules were added */ function getValidationScript() { if (empty($this->_rules) || empty($this->_attributes['onsubmit'])) { return ''; } include_once('HTML/QuickForm/RuleRegistry.php'); $registry =& HTML_QuickForm_RuleRegistry::singleton(); $test = array(); $js_escape = array( "\r" => '\r', "\n" => '\n', "\t" => '\t', "'" => "\\'", '"' => '\"', '\\' => '\\\\' ); foreach ($this->_rules as $elementName => $rules) { foreach ($rules as $rule) { if ('client' == $rule['validation']) { unset($element); $dependent = isset($rule['dependent']) && is_array($rule['dependent']); $rule['message'] = strtr($rule['message'], $js_escape); if (isset($rule['group'])) { $group =& $this->getElement($rule['group']); // No JavaScript validation for frozen elements if ($group->isFrozen()) { continue 2; } $elements =& $group->getElements(); foreach (array_keys($elements) as $key) { if ($elementName == $group->getElementName($key)) { $element =& $elements[$key]; break; } } } elseif ($dependent) { $element = array(); $element[] =& $this->getElement($elementName); foreach ($rule['dependent'] as $idx => $elName) { $element[] =& $this->getElement($elName); } } else { $element =& $this->getElement($elementName); } // No JavaScript validation for frozen elements if (is_object($element) && $element->isFrozen()) { continue 2; } elseif (is_array($element)) { foreach (array_keys($element) as $key) { if ($element[$key]->isFrozen()) { continue 3; } } } $test[$elementName][] = $registry->getValidationScript($element, $elementName, $rule); } } } $js = ' '; return $js; } // end func getValidationScript // }}} function display() { $this->getValidationScript(); return parent::display(); } } ?>