Re: [SMARTY-DEV] html_options optgroup support

From: Date: Fri, 01 Nov 2002 15:21:12 +0000
Subject: Re: [SMARTY-DEV] html_options optgroup support
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-312@lists.php.net to get a copy of this message
Great idea. I rewrote the function to support recursion, and as a result cleaned up the html_option function to work more modularly. I committed the changes to CVS, let me know if anything doesn't work right. On Fri, 2002-11-01 at 06:00, Robert Amos wrote: > I wrote this up for a project im working on, thought I might submit it > in case anyone else finds it useful. It implements <optgroup> tag > support as per the HTML 4 specifications > (http://www.w3.org/TR/html4/interact/forms.html#edef-OPTGROUP). > > To make an optgroup, when you use the associative array option with > {html_options} you set the output values to arrays. > > It's not infinitely recursive though, if I get bored I might work on > that. > > -Robert > > > --- function.html_options.php.old Tue Oct 29 02:20:08 2002 > +++ function.html_options.php Tue Oct 29 02:10:27 2002 > @@ -21,10 +21,21 @@ > if (isset($options)) { > settype($options, 'array'); > foreach ($options as $key => $value) { > - $html_result .= "<option value=\"$key\""; > - if (in_array($key, $selected)) > - $html_result .= " selected=\"selected\""; > - $html_result .= ">$value</option>\n"; > + if (is_array($value)) { > + $html_result .= "<optgroup label=\"$key\">\n"; > + foreach ($value as $k => $v) { > + $html_result .= "<option value=\"$k\""; > + if (in_array($k, $selected)) > + $html_result .= " selected=\"selected\""; > + $html_result .= ">$v</option>\n"; > + } > + $html_result .= "</optgroup>\n"; > + } else { > + $html_result .= "<option value=\"$key\""; > + if (in_array($key, $selected)) > + $html_result .= " selected=\"selected\""; > + $html_result .= ">$value</option>\n"; > + } > } > } else { > settype($output, 'array'); > > -- > Smarty Development Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- Monte Ohrt <monte@ispi.net>

« previous php.smarty.dev (#312) next »