Welcome Guest, Not a member yet? Register   Sign In
Its a bug in form_helper's form_dropdown function ?
#1

[eluser]CodeIgniter Fan[/eluser]
If dropdown contains two values one value is empty string "" and other is "0" and if we have set empty string "" or "0" as selected than the statement at line 235 in file form_helper.php

Code:
$sel = ($selected != $key) ? '' : ' selected="selected"'


will evaluate to false for both value empty string "" and "0" and both option will be selected because ternary conditional operator will evaluate first sub-expression when statement ($selected != $key) is true and second sub-expression if ($selected != $key) is false.

But when I change the statement at line 235 to this:

Code:
$sel = (strcmp($selected,$key)) ? '' : ' selected="selected"';

than only one option is selected that we have said to set selected from "" or "0" becuase php strcmp function only returns 0 when both string are equal for example,

Code:
strcmp("","0") will return -1 and the above ternary statement will give '' as result
and
Code:
strcmp("","") or strcmp("0","0") will return 0 and the above ternary statement will give ' selected="selected"' as result

So I think that php may be parsing "0" as an empty string and the expression- ($selected != $key) evalutes to false when $selected="" and $key="" or $key="0".

Thus guys give your suggestions and if it is a bug than we post it as a bug on bug tracker.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB