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.


Messages In This Thread
Fixing re-population of checkbox arrays - by El Forum - 01-26-2008, 05:17 AM
Fixing re-population of checkbox arrays - by El Forum - 01-26-2008, 10:08 AM
Fixing re-population of checkbox arrays - by El Forum - 01-26-2008, 10:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB