Re-populate checkbox if it fails in validation in an edit form in Codeigniter

前端 未结 5 383
谎友^
谎友^ 2021-01-16 18:13

I works on the an data-edit form in codeigintier. And the problem is about re-populate checkbox

It works if it is an add form (that means I need not concern about th

5条回答
  •  渐次进展
    2021-01-16 19:09

    In order to re-populate checkbox following code might be helpful:

    set_checkbox('fieldName', 'fieldValue');
    

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

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

    Now if you are on edit form then below code might help you

    $getVal=$valFromDb; //$valFromDb is actually value of the filed from db as you are on edit page
    if($getVal!=0){
    {
       echo form_checkbox('fieldName[]', 'value', true);
    }
    else
    {
       echo form_checkbox('fieldName[]', 'value', false);
    }
    

提交回复
热议问题