html_options optgroup support

From: Date: Fri, 01 Nov 2002 12:00:55 +0000
Subject: html_options optgroup support
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-311@lists.php.net to get a copy of this message
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');

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