Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{html_options} selected option bug

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
mpapec
Smarty n00b


Joined: 12 May 2010
Posts: 3

PostPosted: Wed May 12, 2010 5:17 pm    Post subject: {html_options} selected option bug Reply with quote

<?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
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Wed May 12, 2010 5:41 pm    Post subject: Re: {html_options} selected option bug Reply with quote

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
View user's profile Send private message
mpapec
Smarty n00b


Joined: 12 May 2010
Posts: 3

PostPosted: Wed May 12, 2010 6:22 pm    Post subject: Reply with quote

php sucks, I know. Smile

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed May 12, 2010 7:33 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mpapec
Smarty n00b


Joined: 12 May 2010
Posts: 3

PostPosted: Thu May 13, 2010 2:51 pm    Post subject: Reply with quote

Maybe; I'm leaving this decision to the smarty development team.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP