Html_options selecting more than one value
| From: | Robert V. Zwink | Date: | Wed, 20 Nov 2002 21:42:49 +0000 |
| Subject: | Html_options selecting more than one value | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-6482@lists.php.net to get a copy of this message | ||
I'm not sure if this has been brought up before in the past, but I
thought it was worth mentioning as this has proven relatively difficult
to troubleshoot. I do not have a question, rather a solution that may
help someone browsing the archives.
I have an array of possible values that looks like this:
$f = array_merge(range('A', 'Z'), range(0, 9), array("."));
Which just creates an array of capital A-Z 1-9 and the period "." The
problem I found is that when I use html_options to generate a list of
options from this array:
{html_options options=$f selected=$selected}
And set the value of $selected to a letter like "L" the resulting
options will have two items selected. "L" and "0" (zero). So my output
will resemble
<..snip...>
<option value="I" selected="selected">I</option>
<option value="J">J</option>
<option value="K">K</option>
<option value="L">L</option>
<option value="M">M</option>
<option value="N">N</option>
<option value="O">O</option>
<..snip...>
<option value="Z">Z</option>
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<..snip...>
This appears to be caused by this line in the file
/plugins/function.html_options.php:
if (in_array($key, $selected))
I changed this line to instead read:
if (in_array($key, $selected, TRUE))
Which forces the in_array() function to check variable types, and
everything is working fine now. I just thought this was interesting.
Maybe it will help someone, maybe it will not. Regardless have a nice
day, and thanks for a wonderful script. I think Smarty is great!
Thanks!
Robert V. Zwink
http://www.snpaa.org - The Short North Performing Arts
Association, Inc.
(SNPAA) is committed to expanding the musical horizons of Columbus, Ohio
residents by presenting classical and world folk music performances in
tradition and non-traditional venues
http://www.striezelmarkt.org - Striezelmarkt is a unique
family holiday
activity for Central Ohio residents that is made possible through our
Dresden Sister City partnership.
http://www.zwink.net - Homepage of Robert and Antje Zwink
http://www.bellallusions.com - Bellallusions offers faux
finishing,
decorative painting and stenciling in Columbus and Central Ohio.