CodeIgniter 2.0 - validating arrays

后端 未结 1 1280
抹茶落季
抹茶落季 2021-01-06 12:38

I\'m having some problems converting a piece of form validation code to CI 2.0. I\'m trying to validate an array of checkboxes but for some reason validation fails to run th

1条回答
  •  一整个雨季
    2021-01-06 13:11

    An array must be passed to your set_rules call suffixed with opening / closing square brackets, like so:

    $this->form_validation->set_rules('checkboxes[]', 'My Checkboxes', 'required');
    

    There are more details in the CI user guide - https://www.codeigniter.com/user_guide/libraries/form_validation.html#using-arrays-as-field-names

    To handle the check for your checkbox values to be one of several values, you would need to create a custom callback function - https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods

    0 讨论(0)
提交回复
热议问题