Welcome Guest, Not a member yet? Register   Sign In
Fixing re-population of checkbox arrays
#1

[eluser]marlar[/eluser]
Hi,

Being still new to CI it is sometimes difficult to know if I am doing something wrong or if I happened to find a bug. In this case I believe I found a bug in the validation library.

The problem is that checkboxes don't get re-populated if they are part of a group, like:
Code:
echo form_checkbox('group[]','family', $this->validation->set_checkbox('group', 'family'));
echo form_checkbox('group[]','friends', $this->validation->set_checkbox('group', 'friends'));

I changed set_checkbox() in the validation libary to:
Code:
function set_checkbox($field = '', $value = '')
    {
        if ($field == '' OR $value == '' OR  ! isset($_POST[$field]))
        {
            return '';
        }
            
        //Before: if ($_POST[$field] == $value)
        if ($_POST[$field] == $value || ( is_array($_POST[$field]) && in_array($value, $_POST[$field])) )
        {
            return ' checked="checked"';
        }
    }
and now it seems to work as expected.
#2

[eluser]Tom Glover[/eluser]
Could be a bug Undecided , post it in the bug forum and tracker and see what they say. Im still new to CI but i can normally see a bug a mile off Smile .
#3

[eluser]marlar[/eluser]
Good idea.

http://ellislab.com/forums/viewthread/69949/




Theme © iAndrew 2016 - Forum software by © MyBB