cvs: pear /HTML_QuickForm/QuickForm select.php

From: Date: Tue, 18 Feb 2003 13:25:59 +0000
Subject: cvs: pear /HTML_QuickForm/QuickForm select.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8932@lists.php.net to get a copy of this message
mansion Tue Feb 18 08:25:59 2003 EDT Modified files: /pear/HTML_QuickForm/QuickForm select.php Log: Fix a bug with select when multiple is set. QuickForm could not find the element. Index: pear/HTML_QuickForm/QuickForm/select.php diff -u pear/HTML_QuickForm/QuickForm/select.php:1.16 pear/HTML_QuickForm/QuickForm/select.php:1.17 --- pear/HTML_QuickForm/QuickForm/select.php:1.16 Sun Dec 8 18:01:22 2002 +++ pear/HTML_QuickForm/QuickForm/select.php Tue Feb 18 08:25:59 2003 @@ -3,7 +3,7 @@ // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ -// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | +// | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: select.php,v 1.16 2002/12/08 23:01:22 mansion Exp $ +// $Id: select.php,v 1.17 2003/02/18 13:25:59 mansion Exp $ require_once('HTML/QuickForm/element.php'); @@ -147,7 +147,7 @@ */ function setName($name) { - $this->updateAttributes(array('name'=>$name)); + $this->updateAttributes(array('name' => $name)); } //end func setName // }}} @@ -167,6 +167,26 @@ } //end func getName // }}} + // {{{ getPrivateName() + + /** + * Returns the element name + * + * @since 1.0 + * @access public + * @return string + * @throws + */ + function getPrivateName() + { + if ($this->getAttribute('multiple')) { + return $this->getName() . '[]'; + } else { + return $this->getName(); + } + } //end func getPrivateName + + // }}} // {{{ setValue() /** @@ -247,14 +267,8 @@ function setMultiple($multiple) { if ($multiple) { - if (substr($this->getName(), -2) != '[]') { - $this->setName($this->getName() . '[]'); - } - $this->updateAttributes(array("multiple")); + $this->updateAttributes(array("multiple" => "multiple")); } else { - if (substr($this->getName(), -2) == '[]') { - $this->setName(substr($this->getName(), 0, -2)); - } $this->removeAttribute('multiple'); } } //end func setMultiple @@ -386,7 +400,7 @@ function loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null) { if (is_string($conn)) { - require_once('DB.php'); + require_once('DB.php'); $dbConn = &DB::connect($conn, true); if (DB::isError($dbConn)) return $dbConn; } elseif (is_subclass_of($conn, "db_common")) { @@ -456,13 +470,7 @@ if ($this->_flagFrozen) { $strHtml = $this->getFrozenHtml(); } else { - // put this down here since it changes the name - if ($this->getAttribute('multiple')) { - $this->setMultiple(true); - } - $tabs = $this->_getTabs(); - $name = isset($this->_attributes['name']) ? $this->_attributes['name'] : '' ; $strHtml = ''; @@ -470,7 +478,12 @@ $strHtml .= $tabs . '<!-- ' . $this->getComment() . " //-->\n"; } - $strHtml .= $tabs . '<select' . $this->_getAttrString($this->_attributes) . ">\n"; + if ($this->getMultiple()) { + $attrString = preg_replace('/name="([^"]*)"/', 'name="'.$this->getName().'[]"', $this->_getAttrString($this->_attributes)); + } else { + $attrString = $this->_getAttrString($this->_attributes); + } + $strHtml .= $tabs . '<select' . $attrString . ">\n"; for ($counter=0; $counter < count($this->_options); $counter++) { $value = $this->_options[$counter]["attr"]["value"]; @@ -487,7 +500,6 @@ $strHtml .= $tabs . '</select>'; } - return $strHtml; } //end func toHtml @@ -527,7 +539,7 @@ if (is_array($value)) { $html = join('<br />', $value); if ($this->_persistantFreeze) { - $name = $this->getName(); + $name = $this->getPrivateName(); foreach ($value as $key => $item) { $html .= '<input type="hidden" name="' . $name . '" value="' . $this->_values[$key] . '" />'; @@ -541,7 +553,7 @@ } if ($this->_persistantFreeze) { $html .= '<input type="hidden" name="' . - $this->getName() . '" value="' . $value . '" />'; + $this->getPrivateName() . '" value="' . $value . '" />'; } } return $html; @@ -550,4 +562,4 @@ // }}} } //end class HTML_QuickForm_select -?> +?> \ No newline at end of file

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