Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter form set_radio bug?
#1

[eluser]dignick[/eluser]
I'm using set_radio to fill in a radio field. If the value of the radio is 0, then CodeIgniter will not set the radio to checked.

The reason for this is that the value being passed to set_radio is a numerical 0 and the condition (0 == '') returns true, which is tested near the bottom of the set_radio function in the Form_validation library:
Code:
if (($field == '' OR $value == '') OR ($field != $value))
{
    return '';
}

It is the $value == '' test that is the problem here. If this is changed to $value === '' the field gets checked as expected.

The problem is set_radio expects a string to be passed to it, but should it not also work with a number?
#2

[eluser]dignick[/eluser]
Another way to prevent this issue is to cast the passed $value parameter as a string when passing it. Shouldn't this be dealt with in CodeIgniter though?




Theme © iAndrew 2016 - Forum software by © MyBB