Codeigniter - form validation converting Array's post variables to & ldquo; Array & rdquo; chain

advertisements

I am building an HTML form with a set of checkboxes for selecting multiple categories using this format:

<input type="checkbox" name="category[]" />

So, when I post and print_r($_POST) to view the variable and values I get:

Array
(
    [27] => on
    [28] => on
    [29] => on
)

Once I run $this->form_validation->run(); the categories array becomes "Array" as a string. I believe I have narrowed it down to "prep_for_form" function in the system/libraries/Form_validation.php file, but it seems like the recursive function is working correctly.

Thank you in advance.


I figured it out. When using the $this->form_validation->set_rules() method, in the validation rules (third parameter) I set it to trim|required. I guess the trim function treats the actual Array like a string "Array" and trims the word. I simply removed the "trim" rule from my validation rules. e.g.

$this->form_validation->set_rules('category', 'categories', 'trim|required');

// when parsing an array (set of checkboxes, radio buttons, etc.)
// - remove the "trim" validation
$this->form_validation->set_rules('category', 'categories', 'required');

I hope others find this useful.