|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
mpapec Smarty n00b
Joined: 12 May 2010 Posts: 3
|
Posted: Wed May 12, 2010 5:17 pm Post subject: {html_options} selected option bug |
|
|
<?php
$smarty->assign('myOptions', array(
"001" => 'Joe Schmoe',
"01" => 'Jack Smith',
"1" => 'Charlie Brown')
);
$smarty->assign('mySelect', "01");
?>
{html_options name=foo options=$myOptions selected=$mySelect}
It doesn't select proper option in function.html_options.php
instead:
if (in_array((string)$key, $selected))
should probably be:
if (in_array((string)$key, $selected, true))
I think there is the same issue with radios and checkboxes. |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Wed May 12, 2010 5:41 pm Post subject: Re: {html_options} selected option bug |
|
|
mpapec wrote: | <?php
$smarty->assign('myOptions', array(
"001" => 'Joe Schmoe',
"01" => 'Jack Smith',
"1" => 'Charlie Brown')
);
$smarty->assign('mySelect', "01");
?>
{html_options name=foo options=$myOptions selected=$mySelect}
It doesn't select proper option in function.html_options.php
instead:
if (in_array((string)$key, $selected))
should probably be:
if (in_array((string)$key, $selected, true))
I think there is the same issue with radios and checkboxes. |
only thing with the strict check is, what if array is defined as
Quote: |
$smarty->assign('myOptions', array(
1 => 'Joe Schmoe',
2 => 'Jack Smith',
3 => 'Charlie Brown')
);
|
|
|
Back to top |
|
mpapec Smarty n00b
Joined: 12 May 2010 Posts: 3
|
Posted: Wed May 12, 2010 6:22 pm Post subject: |
|
|
php sucks, I know.
It should be always forced strings on user array keys, and stict checks should be used.
Is there a better way to solve this issue? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed May 12, 2010 7:33 pm Post subject: |
|
|
You could add a param to the html_options function:
{html_options ... strict=true}
Then do the appropriate thing inside the plugin. |
|
Back to top |
|
mpapec Smarty n00b
Joined: 12 May 2010 Posts: 3
|
Posted: Thu May 13, 2010 2:51 pm Post subject: |
|
|
Maybe; I'm leaving this decision to the smarty development team. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|