From 87a78d3b8e0e13677ceb3b5b7f5378864f907b7c Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 17 Mar 2010 14:56:18 +0000 Subject: 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 --- views/default/input/pulldown.php | 24 +++++++++++++----------- 1 file 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 ""; + $encoded_value = htmlentities($value, ENT_QUOTES, 'UTF-8'); + $encoded_option = htmlentities($option, ENT_QUOTES, 'UTF-8'); + + if ((string)$value == (string)$vars['value']) { + echo ""; } else { - echo ""; + echo ""; } } } 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 ""; + if ((string)$value == (string)$vars['value']) { + echo ""; } else { - echo ""; + echo ""; } } } -- cgit v1.2.3