Re: My little update to HTML_OPTIONS

From: Date: Thu, 20 Sep 2001 16:50:55 +0000
Subject: Re: My little update to HTML_OPTIONS
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1498@lists.php.net to get a copy of this message
Is this syntax compatible with all browsers? LIMBOURG Arnaud wrote: > > 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; > } > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

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