Re: html_options

messju mohr <[email protected]> Mon, 26 Feb 2007 09:42:37 +0100
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
Hi,

what about multiple selected values, then?

IMHO this is not a bug in html_options(), it's an incostistency in
php's type system. php does not support boolean values as array keys,
so don't use them as such.

On Sat, Feb 24, 2007 at 07:39:05PM +0100, Danilo Buerger wrote:
> Hey list,
> 
> User Sweetums recently asked on the IRC channel about a weird problem in 
> html_options. See this code snipet:
> 
> --- template ---
> {html_options name=foo options=$myOptions selected=$mySelect}
> 
> --- .php ---
> $smarty->assign('myOptions', array(true => 'test', false => 'foo'));
> $smarty->assign('mySelect', false);
> $smarty->display('test.tpl');
> 
> This will not select foo as default option because the boolean in select 
> is casted to a string (resulting in an empty string) but in options the 
> boolean is casted to an int (resulting in 0). This patch should fix it up:
> 
> Index: plugins/function.html_options.php
> ===================================================================
> RCS file: /repository/smarty/libs/plugins/function.html_options.php,v
> retrieving revision 1.25
> diff -r1.25 function.html_options.php
> 58c58
> <                 $$_key = array_map('strval', array_values((array)$_val));
> ---
> >                 $$_key = $_val;
> 102c102
> <         if (in_array((string)$key, $selected))
> ---
> >         if ((string)$key == $selected)
> 
> -- 
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php