Unchecked checkbox returning null value

后端 未结 5 1112
生来不讨喜
生来不讨喜 2020-12-09 05:23

I have a set of checkboxes which when checked they pass the value as 1, otherwise they pass the value as 0. However, instead of sending the value of the unchecked checkboxe

5条回答
  •  再見小時候
    2020-12-09 05:58

    You can try this , it may help you. Assume your form is like this:

    
      Active
      active),TRUE); ?>  
    
    

    Now you set your codeigniter controller like this:

    // Set up the form
    $rules = $this->student_m->rules;
    $this->form_validation->set_rules($rules);
    
    // Process the form
    if ($this->form_validation->run() == TRUE) {
       $data = $this->student_m->array_from_post(array(
               'active',
               'name'
       ));
    
       // checking is checkbox is checked or not
       ($data['active'] == TRUE)?($data['active'] = 1) : ($data['active'] = 0);
    
       $this->student_m->save($data, $id);
       redirect('admin/student');
    }
    

提交回复
热议问题