cvs: pear /HTML_QuickForm QuickForm.php /HTML_QuickForm/QuickForm element.php

From: Date: Sat, 01 Feb 2003 17:56:15 +0000
Subject: cvs: pear /HTML_QuickForm QuickForm.php /HTML_QuickForm/QuickForm element.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8643@lists.php.net to get a copy of this message
mansion Sat Feb 1 12:56:15 2003 EDT Modified files: /pear/HTML_QuickForm QuickForm.php /pear/HTML_QuickForm/QuickForm element.php Log: Added partial support for element names with brackets like: name="form[name][first]" Index: pear/HTML_QuickForm/QuickForm.php diff -u pear/HTML_QuickForm/QuickForm.php:1.52 pear/HTML_QuickForm/QuickForm.php:1.53 --- pear/HTML_QuickForm/QuickForm.php:1.52 Sat Feb 1 11:01:31 2003 +++ pear/HTML_QuickForm/QuickForm.php Sat Feb 1 12:56:14 2003 @@ -17,7 +17,7 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: QuickForm.php,v 1.52 2003/02/01 16:01:31 mansion Exp $ +// $Id: QuickForm.php,v 1.53 2003/02/01 17:56:14 mansion Exp $ require_once('PEAR.php'); require_once('HTML/Common.php'); @@ -1429,6 +1429,28 @@ } // end func getRequiredNote // }}} + // {{{ _findValue() + + /** + * Tries to find the element value from the submitted values array + * + * @since 2.7 + * @access private + * @return string + * @throws + */ + function _findElementValue($elementName) + { + if (isset($this->_submitValues[$elementName])) { + $value = $this->_submitValues[$elementName]; + return $value; + } + $myVar = str_replace(array(']', '['), array('', "']['"), $elementName); + $myVar = "['".$myVar."']"; + return eval("return (isset(\$this->_submitValues$myVar)) ? \$this->_submitValues$myVar : null;"); + } //end func _findElementValue + + // }}} // {{{ validate() /** @@ -1453,6 +1475,7 @@ $this->_validateGroup($elementName, $rules, $submitValues); } else { // Standard elements validation + $submitValue = $this->_findElementValue($elementName); foreach ($rules as $rule) { $type = $format = $message = null; $type = $rule['type']; @@ -1467,8 +1490,8 @@ switch ($ruleData[0]) { case 'regex': $regex = str_replace('%data%', $format, $ruleData[1]); - if (!preg_match($regex, $this->_submitValues[$elementName])) { - if (empty($this->_submitValues[$elementName]) && !$this->isElementRequired($elementName)) { + if (!preg_match($regex, $submitValue)) { + if (empty($submitValue) && !$this->isElementRequired($elementName)) { continue 2; } else { $this->_errors[$elementName] = $message; @@ -1478,8 +1501,8 @@ break; case 'function': if (method_exists($this, $ruleData[1])) { - if (isset($this->_submitValues[$elementName])) { - $element = $this->_submitValues[$elementName]; + if (isset($submitValue)) { + $element = $submitValue; } elseif (isset($this->_submitFiles[$elementName])) { $element = $this->_submitFiles[$elementName]; } @@ -1488,7 +1511,7 @@ continue 2; } } else { - if (!$ruleData[1]($elementName, $this->_submitValues[$elementName], $format)) { + if (!$ruleData[1]($elementName, $submitValue, $format)) { $this->_errors[$elementName] = $message; continue 2; } Index: pear/HTML_QuickForm/QuickForm/element.php diff -u pear/HTML_QuickForm/QuickForm/element.php:1.16 pear/HTML_QuickForm/QuickForm/element.php:1.17 --- pear/HTML_QuickForm/QuickForm/element.php:1.16 Fri Jan 10 07:31:54 2003 +++ pear/HTML_QuickForm/QuickForm/element.php Sat Feb 1 12:56:14 2003 @@ -17,7 +17,7 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: element.php,v 1.16 2003/01/10 12:31:54 mansion Exp $ +// $Id: element.php,v 1.17 2003/02/01 17:56:14 mansion Exp $ require_once('HTML/Common.php'); @@ -320,6 +320,33 @@ } //end func getLabel // }}} + // {{{ _findValue() + + /** + * Tries to find the element value from the submitted values array + * + * @since 2.7 + * @access private + * @return string + * @throws + */ + function _findValue(&$values) + { + if (empty($values)) return; + $elementName = $this->getName(); + if (isset($values[$elementName])) { + $value = $values[$elementName]; + if (is_string($value) && get_magic_quotes_gpc() == 1) { + $value = stripslashes($value); + } + return $value; + } + $myVar = str_replace(array(']', '['), array('', "']['"), $elementName); + $myVar = "['".$myVar."']"; + return eval("return (isset(\$values$myVar)) ? \$values$myVar : null;"); + } //end func _findValue + + // }}} // {{{ onQuickFormEvent() /** @@ -344,24 +371,15 @@ case 'createElement': $this->$className($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]); // need to set the submit value in case setDefault never gets called - $elementName = $this->getName(); - if (isset($caller->_submitValues[$elementName])) { - $value = $caller->_submitValues[$elementName]; - if (is_string($value) && get_magic_quotes_gpc() == 1) { - $value = stripslashes($value); - } + $value = $this->_findValue($caller->_submitValues); + if (!is_null($value)) { $this->setValue($value); } break; case 'setDefault': // In form display, default value is always overidden by submitted value - $elementName = $this->getName(); - if (isset($caller->_submitValues[$elementName])) { - $value = $caller->_submitValues[$elementName]; - if (is_string($value) && get_magic_quotes_gpc() == 1) { - $value = stripslashes($value); - } - } else { + $value = $this->_findValue($caller->_submitValues); + if (is_null($value)) { $value = $arg; } $this->setValue($value); @@ -376,7 +394,7 @@ break; } return true; - } // end func onQuickFormLoad + } // end func onQuickFormEvent // }}}

« previous php.pear.cvs (#8643) next »