cvs: pear /HTML_QuickForm/QuickForm checkbox.php

From: Date: Sun, 02 Feb 2003 16:42:45 +0000
Subject: cvs: pear /HTML_QuickForm/QuickForm checkbox.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8682@lists.php.net to get a copy of this message
mansion Sun Feb 2 11:42:45 2003 EDT Modified files: /pear/HTML_QuickForm/QuickForm checkbox.php Log: Setting and validating values in checkboxes should now work even if their name is like: checkbox[A] and even if they are not part of a group. Index: pear/HTML_QuickForm/QuickForm/checkbox.php diff -u pear/HTML_QuickForm/QuickForm/checkbox.php:1.7 pear/HTML_QuickForm/QuickForm/checkbox.php:1.8 --- pear/HTML_QuickForm/QuickForm/checkbox.php:1.7 Sun Dec 15 06:45:08 2002 +++ pear/HTML_QuickForm/QuickForm/checkbox.php Sun Feb 2 11:42:45 2003 @@ -17,7 +17,7 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: checkbox.php,v 1.7 2002/12/15 11:45:08 mansion Exp $ +// $Id: checkbox.php,v 1.8 2003/02/02 16:42:45 mansion Exp $ require_once("HTML/QuickForm/input.php"); @@ -208,6 +208,31 @@ } // end func getValue // }}} + // {{{ _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]; + return $value; + } + $myVar = str_replace(array(']', '['), array('', "']['"), $elementName); + $myVar = "['".$myVar."']"; + $value = eval("return (isset(\$values$myVar)) ? \$values$myVar : null;"); + return $value; + } //end func _findValue + + // }}} // {{{ onQuickFormEvent() /** @@ -229,18 +254,18 @@ case 'createElement': $this->$className($arg[0], $arg[1], $arg[2], $arg[3]); // need to set the submit value in case setDefault never gets called - $elementName = $this->getName(); - if (isset($caller->_submitValues) && count($caller->_submitValues) > 0) { - $tmp_checked = isset($caller->_submitValues[$elementName]) ? $caller->_submitValues[$elementName] : false; - $this->setChecked($tmp_checked); + $value = $this->_findValue($caller->_submitValues); + if (!is_null($value)) { + $this->setChecked($value); } break; case 'setDefault': // In form display, default value is always overidden by submitted value - $elementName = $this->getName(); if (count($caller->_submitValues) > 0) { - $tmp_checked = isset($caller->_submitValues[$elementName]) ? $caller->_submitValues[$elementName] : false; - $this->setChecked($tmp_checked); + $value = $this->_findValue($caller->_submitValues); + if (!is_null($value)) { + $this->setChecked($value); + } } else { $this->setChecked($arg); }

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