Repopulating checkboxes in Codeigniter after Unsuccessful Form Validation

前端 未结 9 902
梦毁少年i
梦毁少年i 2021-02-04 16:18

I have a problem repopulating a set of checkboxes after an unsuccessful form validation returns the user back to the same form. Dropdown menus and text inputs could be repopulat

9条回答
  •  心在旅途
    2021-02-04 16:35

    You set_checkbox calls are wrong. When you're using an array like "ambience[]" in form_checkbox, you don't want to include the square brackets ([]) in your set_checkbox call. The other problem is that set_checkbox requires a second parameter which you've only included in the first 2 checkboxes.

    The set_checkbox should always be like this:

    set_checkbox('ambience', 'value');
    

    Where 'value' is the second parameter of the form_checkbox call. Like this:

    form_checkbox('ambience[]', 'value', set_checkbox('ambience', 'value'));
    

提交回复
热议问题