My little update to HTML_OPTIONS

From: Date: Thu, 20 Sep 2001 13:07:55 +0000
Subject: My little update to HTML_OPTIONS
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1494@lists.php.net to get a copy of this message
Hello, For those of you who are interested, here is my little update to the html_options functions to make it more XHTML compliant. The change is just on the <option value="foo" selected="foo"> instead of <option value="foo" selected> I cannot put these anywhere else since my firewall blocks everything. Arnaud. /*======================================================================*\ Function: smarty_func_html_options Purpose: Prints the list of <option> tags generated from the passed parameters \*======================================================================*/ function smarty_func_html_options() { $print_result = true; extract(func_get_arg(0)); $html_result = ""; settype($selected, 'array'); if (isset($options)) { settype($options, 'array'); foreach ($options as $key => $value) { $html_result .= "<option value=\"$key\""; if (in_array($key, $selected)) $html_result .= " selected=\"$key\""; $html_result .= ">$value</option>\n"; } } else { settype($output, 'array'); settype($values, 'array'); for ($i = 0; $i < count($output); $i++) { /* By default, check value against $selected */ $sel_check = $values[$i]; $html_result .= '<option'; if ($i < count($values)) $html_result .= ' value="'.$values[$i].'"'; else $sel_check = $output[$i]; /* if more outputs than values, then check output against $selected */ if (in_array($sel_check, $selected)) $html_result .= " selected=\"$key\""; $html_result .= '>'.$output[$i]."</option>\n"; } } if ($print_result) print $html_result; else return $html_result; }

« previous php.smarty.general (#1494) next »