Howto require just one element of a form? |
[eluser]wdcmatt[/eluser]
I have an html form that is 20 check boxes. (A list of user groups...) I have to ensure that AT LEAST ONE is checked, more is fine, but any of them is acceptable. (I must ensure that each user is a member of at least 1 group... they can be members of more but must have at least one group.) I know ci has the "required" tag in form validation is there something handy I could use to require one out of a list of variables? I know how to do this with standard php, but was just curious if there was a nice feature of ci that could manage this for me. Thanks in advance. wdcmatt
[eluser]OliverHR[/eluser]
You must use a custom validation, I mean your own callback function to see if at least one item is checked. See this: Callbacks: Your own Validation Functions
[eluser]theshiftexchange[/eluser]
This does it - it forces uses to check AT LEAST one of the 3 checkboxes below. The key is you need them as an "array" - not as individual checkbox variables. Controller: Code: $this->form_validation->set_rules('sector_list[]','Sector Selection', 'required'); View: Code: <input type="checkbox" name="sector_list[]" value="road_north" <?php echo set_checkbox('sector_list[]', 'road_north', $road_north); ?> /></td>
[eluser]wdcmatt[/eluser]
Good thinkin' I like. I'll give that a shot. Thanks. |
Welcome Guest, Not a member yet? Register Sign In |