cvs: pear /HTML_QuickForm/Elements select.php

From: Date: Thu, 31 Jan 2002 18:28:23 +0000
Subject: cvs: pear /HTML_QuickForm/Elements select.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-2260@lists.php.net to get a copy of this message
mansion Thu Jan 31 13:28:23 2002 EDT Modified files: /pear/HTML_QuickForm/Elements select.php Log: More consistency with HTML_Select coding style xHTML impovements single quotes Index: pear/HTML_QuickForm/Elements/select.php diff -u pear/HTML_QuickForm/Elements/select.php:1.4 pear/HTML_QuickForm/Elements/select.php:1.5 --- pear/HTML_QuickForm/Elements/select.php:1.4 Mon Jan 21 07:42:14 2002 +++ pear/HTML_QuickForm/Elements/select.php Thu Jan 31 13:28:23 2002 @@ -17,9 +17,9 @@ // | Bertrand Mansion <bmansion@mamasam.com> | // +----------------------------------------------------------------------+ // -// $Id: select.php,v 1.4 2002/01/21 12:42:14 mansion Exp $ +// $Id: select.php,v 1.5 2002/01/31 18:28:23 mansion Exp $ -require_once("HTML/QuickForm/Elements/element.php"); +require_once('HTML/QuickForm/Elements/element.php'); /** * Class to dynamically create an HTML SELECT @@ -65,8 +65,8 @@ function HTML_QuickForm_select ($elementName=null, $options=null, $attributes=null) { HTML_QuickForm_element::HTML_QuickForm_element('select', $elementName, null, $attributes); - if ($this->getAttribute("multiple") AND strpos($elementName,"]")<2) - $elementName = $elementName."[]"; + if ($this->getAttribute('multiple') AND strpos($elementName,']')<2) + $elementName = $elementName.'[]'; if (isset($options)) { $this->load($options); } @@ -180,7 +180,7 @@ */ function setSize($size) { - $this->updateAttributes(array("size"=>$size)); + $this->updateAttributes(array('size'=>$size)); } //end func setSize /** @@ -193,7 +193,7 @@ */ function getSize() { - return $this->getAttribute("size"); + return $this->getAttribute('size'); } //end func getSize /** @@ -211,13 +211,13 @@ function addOption($text, $value, $attributes=null) { $attributes = $this->_parseAttributes($attributes); - if ($this->getAttribute("selected") && !in_array($value, $this->_values)) { + if ($this->getAttribute('selected') && !in_array($value, $this->_values)) { $this->_values[] = $value; array_unique($this->_values); } - $attr = array("value"=>$value); + $attr = array('value'=>$value); $this->_updateAttrArray($attributes, $attr); - $this->_options[] = array("text"=>$text, "attr"=>$attributes); + $this->_options[] = array('text'=>$text, 'attr'=>$attributes); } // end func addOption /** @@ -305,10 +305,10 @@ if (is_string($conn)) { $dbConn = &DB::connect($conn, true); if (DB::isError($dbConn)) return $dbConn; - } elseif (is_subclass_of($conn, "db_common")) { + } elseif (is_subclass_of($conn, 'db_common')) { $dbConn = $conn; } else { - return new PEAR_Error("Argument 1 of HTML_Select::loadQuery is not a valid type"); + return new PEAR_Error('Argument 1 of HTML_Select::loadQuery is not a valid type'); } $result = $dbConn->query($sql); if (DB::isError($result)) return $result; @@ -340,10 +340,10 @@ case is_array($options): return $this->loadArray($options, $param1); break; - case (get_class($options) == "db_result" || is_subclass_of($options, "db_result")): + case (get_class($options) == 'db_result' || is_subclass_of($options, 'db_result')): return $this->loadDbResult($options, $param1, $param2, $param3); break; - case (is_string($options) || is_subclass_of($options, "db_common")): + case (is_string($options) || is_subclass_of($options, 'db_common')): return $this->loadQuery($options, $param1, $param2, $param3, $param4); break; } @@ -363,28 +363,22 @@ $strHtml = $this->getFrozenHtml(); } else { $tabs = $this->_getTabs(); - $name = isset($this->_attributes["name"]) ? $this->_attributes["name"] : '' ; - $strHtml = - "\n" . $tabs . "<!-- BEGIN SELECT $name -->\n"; + $name = isset($this->_attributes['name']) ? $this->_attributes['name'] : '' ; + $strHtml = ''; if ($this->_comment) { $strHtml .= $tabs . "<!-- $this->_comment -->\n"; } - $strHtml .= - $tabs . "<SELECT" . $this->_getAttrString($this->_attributes) . ">\n" . - $tabs . "\t<!-- BEGIN OPTIONS $name -->\n"; - for ($counter=0; $counter < count($this->_options); $counter++) { - $value = $this->_options[$counter]["attr"]["value"]; - $attrString = $this->_getAttrString($this->_options[$counter]["attr"]); - if (is_array($this->_values) && in_array($value, $this->_values)) { - $attrString = " SELECTED" . $attrString; + $strHtml .= + $tabs . "<select" . $this->_getAttrString($this->_attributes) . ">\n"; + foreach ($this->_options as $option) { + if (in_array($option['attr']['value'], $this->_values)) { + $option['attr']['selected'] = 'selected'; } + $attrString = $this->_getAttrString($option['attr']); $strHtml .= - $tabs . "\t<OPTION" . $attrString . ">" . - $this->_options[$counter]["text"] . "</OPTION>\n"; + '<option' . $attrString . '>' . $option['text'] . '</option>'; } - $strHtml .= - $tabs . "\t<!-- END OPTIONS $name -->\n" . - $tabs . "</SELECT><!-- END SELECT $name -->"; + $strHtml .= $tabs . '</select>'; } return $strHtml; } //end func toHtml @@ -434,7 +428,7 @@ { $name = $this->getName(); $value = $this->getValue(); - $html = "<INPUT TYPE=\"hidden\" NAME=\"$name\" VALUE=\"$value\">\n"; + $html = "<input type=\"hidden\" name=\"$name\" value=\"$value\">\n"; return $html; } //end func getHidden

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