Repopulating checkboxes in Codeigniter after Unsuccessful Form Validation

前端 未结 9 775
梦毁少年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:49

    I realised that set_checkbox takes 3 parameters :

     set_checkbox(string $checkboxname, string $value, boolean $isChecked);
    

    For example :

     echo form_checkbox('mycbx[]',
                        $item['id'],
                        set_checkbox('mycbx[]', $item['id'], false)
          );
    

    or this way :

    $checkbox = array(
        'name'        => 'mycbx[]',
        'value'       => $item['id'],
        'checked'     => set_checkbox('mycbx[]', $item['id'], false)
    );
    echo form_checkbox($checkbox);
    

提交回复
热议问题