diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-03-17 14:56:18 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-03-17 14:56:18 +0000 |
commit | 87a78d3b8e0e13677ceb3b5b7f5378864f907b7c (patch) | |
tree | ef69aef4ca92088f01b74d2cca80b52f4fa1cf8f /views/default/input | |
parent | 320d0035b6ba5f5078a9ef03ee880403c858e64e (diff) | |
download | elgg-87a78d3b8e0e13677ceb3b5b7f5378864f907b7c.tar.gz elgg-87a78d3b8e0e13677ceb3b5b7f5378864f907b7c.tar.bz2 |
Documented pulldown quirks for NULL and FALSE as values. Fixed bug when calling htmlentities() on the values before testing them.
git-svn-id: http://code.elgg.org/elgg/trunk@5426 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'views/default/input')
-rw-r--r-- | views/default/input/pulldown.php | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/views/default/input/pulldown.php b/views/default/input/pulldown.php index 54764bbd0..a9663ef82 100644 --- a/views/default/input/pulldown.php +++ b/views/default/input/pulldown.php @@ -3,6 +3,8 @@ * Elgg pulldown input * Displays a pulldown input field * + * NB: Default values of FALSE or NULL will match '' (empty string) and not 0. + * * @package Elgg * @subpackage Core * @author Curverider Ltd @@ -21,7 +23,7 @@ if (!$class) { $class = "input_pulldown"; } -if (!isset($vars['value']) || $vars['value'] === FALSE) { +if (!isset($vars['value'])) { $vars['value'] = elgg_get_sticky_value($vars['internalname']); } @@ -31,24 +33,24 @@ if (!isset($vars['value']) || $vars['value'] === FALSE) { if ($vars['options_values']) { foreach($vars['options_values'] as $value => $option) { - $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); - $option = htmlentities($option, ENT_QUOTES, 'UTF-8'); - // use strcmp() because (0 == 'string') is true - if (strcmp($value, $vars['value']) == 0) { - echo "<option value=\"$value\" selected=\"selected\">$option</option>"; + $encoded_value = htmlentities($value, ENT_QUOTES, 'UTF-8'); + $encoded_option = htmlentities($option, ENT_QUOTES, 'UTF-8'); + + if ((string)$value == (string)$vars['value']) { + echo "<option value=\"$encoded_value\" selected=\"selected\">$encoded_option</option>"; } else { - echo "<option value=\"$value\">$option</option>"; + echo "<option value=\"$encoded_value\">$encoded_option</option>"; } } } else { foreach($vars['options'] as $option) { - $option = htmlentities($option, ENT_QUOTES, 'UTF-8'); + $encoded_option = htmlentities($option, ENT_QUOTES, 'UTF-8'); - if (strcmp($value, $vars['value']) == 0) { - echo "<option selected=\"selected\">$option</option>"; + if ((string)$value == (string)$vars['value']) { + echo "<option selected=\"selected\">$encoded_option</option>"; } else { - echo "<option>$option</option>"; + echo "<option>$encoded_option</option>"; } } } |