Cara agar value checkbox bisa multiple

saya ada kolom checkbox asal keterampilan kepala keluarga

saat data yang di input lebih dari satu, maka checkbox nya tidak tercentang tetapi kalo satu bisa

controller form.php

<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Form extends CI_Controller
{
    function __construct(){
        parent::__construct();
        check_not_login();
        $this->load->model('form_m');
    }
	public function index()
	{
        $data['row'] = $this->form_m->get();
		$this->template->load('template', 'form/form_data',$data);
    }


    public function add(){
        $form = new stdClass();
        $form->pap_id = null;
        $form->asal_keterampilan_kk = null;

        $data = array(
            'page' => 'add',
            'row' => $form
        );

        $this->template->load('template', 'form/form_multi',$data );
    }

public function edit($id){
        $query = $this->form_m->get($id);
        if($query->num_rows() > 0){
            $form = $query->row();

            $data = array(
                'page' => 'edit',
                'row' => $form,
            );
            $this->template->load('template', 'form/form_multi',$data);
        }else{
            echo "<script>alert('Data tidak ditemukan');";
            echo "window.location='".site_url('form')."';</script>";
        }
    }

    public function process(){
        $post = $this->input->post(null, TRUE);
        if(isset($_POST['add'])){
            $this->form_m->add($post);
        }else if(isset($_POST['edit'])){
            $this->form_m->edit($post);
        }

        if($this->db->affected_rows() > 0) {
            echo "<script>alert('Data Berhasil di simpan');</script>";
        }
        echo "<script>window.location='".site_url('form')."';</script>";
    }

berikut model edit Form_m.php

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Form_m extends CI_Model
{

    public function get($id = null)
    {
        $this->db->from('form');
        if($id != null){
            $this->db->where('pap_id', $id);
        }
        $query = $this->db->get();
        return $query;

    }

    public function del($id)
    {
        $this->db->where('pap_id',$id);
        $this->db->delete('form');
    }


    public function add($post)
    {
        $params = [
            'asal_keterampilan_kk' => implode(',', $post['asal_keterampilan_kk'])
   ];
        $this->db->insert('form', $params);
    }

    public function edit($post)
    {
        $params = [
            'asal_keterampilan_kk' =>  implode(',',  $post ['asal_keterampilan_kk']),

   ];
        $this->db->where('pap_id', $post['id']);
        $this->db->update('form', $params);
    }

view form_multi.php

 <div class="form-group">
                                <label> Asal keterampilan keterampilan kepala keluarga</label><br>
                                <input type="checkbox" name="asal_keterampilan_kk[]" value="otodidak" <?php if($row->asal_keterampilan_kk=='otodidak')  {echo "checked";}?>> <i>Belajar Sendiri</i>
                                <input type="checkbox" name="asal_keterampilan_kk[]" value="kursus" <?php if($row->asal_keterampilan_kk=='kursus')  {echo "checked";}?>> <i>Mengikuti kursus</i><br>
                                <input type="checkbox" name="asal_keterampilan_kk[]" value="program_pemerintah" <?php if($row->asal_keterampilan_kk=='program_pemerintah')  {echo "checked";}?>> <i>Program Pemerintah</i>
                                <br>
                                <input type="checkbox" name="asal_keterampilan_kk[]" value="lsm"<?php if($row->asal_keterampilan_kk=='lsm')  {echo "checked";}?>> <i>Lsm atau NGO</i>
                                <input type="checkbox" name="asal_keterampilan_kk[]" value="turun_menurun"<?php if($row->asal_keterampilan_kk=='turun_menurun')  {echo "checked";}?>> <i>Turun Menurun</i><br>
                                <input type="checkbox" name="asal_keterampilan_kk[]" value="pelatihan_perusahaan" <?php if($row->asal_keterampilan_kk=='pelatihan_perusahaan')  {echo "checked";}?>> <i>Program pelatihan perusahaan</i><br>
                            </div>

avatar rakhadiasry
@rakhadiasry

4 Kontribusi 0 Poin

Diperbarui 5 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban