Welcome Guest, Not a member yet? Register   Sign In
Creating validation for a checkbox array.
#3

[eluser]Bramme[/eluser]
okay, I'm implementing that tonight :p

Can't access the svn folder from my work atm... Stupid proxy.

Did they include something to prepolute the checkboxes? Because my hacks are rather ugly at the moment. It seems to be working though.

This is smth from my controller:
Code:
if( $this->input->post('categories') != FALSE) {
    $data['checkbox_array'] = $this->input->post('categories');
} else {
    $this->db->where('tutID', $tutID);
    $tutcats_query = $this->db->get('tutorial_categories');
    foreach($tutcats_query->result() as $row) {
        $selected_cats[] = $row->catID;
    }
    $data['checkbox_array'] = $selected_cats;
}
in my view i've got
Code:
<input type="checkbox" name="categories[]" value="<?=$cat['catID']?>" id="cat-<?=$cat['catID']?>" <?php echo $this->validation->set_checkbox_array($cat['catID'], $checkbox_array); ?>/>
And in MY_Validation.php
Code:
function set_checkbox_array($needle = '', $haystack = array())
{
    if(empty($needle) OR empty($haystack))
    {
        return FAlSE;
    }
    else if (in_array($needle, $haystack))
    {
        return 'checked="checked"';
    }
    else
    {
        return FAlSE;
    }
}


Messages In This Thread
Creating validation for a checkbox array. - by El Forum - 09-12-2008, 06:04 AM
Creating validation for a checkbox array. - by El Forum - 09-12-2008, 06:20 AM
Creating validation for a checkbox array. - by El Forum - 09-12-2008, 06:38 AM
Creating validation for a checkbox array. - by El Forum - 09-26-2008, 12:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB