fungsi yang digunakan agar form tetap dapat disimpan walaupun ada form yang kosong

public function input_detil() {
        $p = $this->input->get();

        if (array_key_exists("is_only_statistik_update", $p)) {
            $url_new = base_url('index.php/statistik_strategis/input_detil?'.http_build_query($p));
        } else {
            $url_new = base_url('index.php/statistik_strategis/input_detil?'.http_build_query($p)."&is_only_statistik_update=1");
        }

        $this->db->where('tahun', $p['tahun']);
        $get_data = $this->db->get('data_statistik_strategis_data')->result_array();

        $tampung_data_detil = array();

        if (!empty($get_data)) {
            foreach ($get_data as $data_detil) {
                $idx1 = $data_detil['id_ref'];
                $idx2 = $data_detil['tahun'];

                $tampung_data_detil[$idx1][$idx2]['val'] = $data_detil['isi'];
                $tampung_data_detil[$idx1][$idx2]['status'] = $data_detil['status_data'];
            }
        }

        // get elemen
        $this->db->order_by('kode1', 'asc');
        $this->db->order_by('kode2', 'asc');
        if (!empty($p['is_only_statistik_update'])) {
            if ($p['is_only_statistik_update'] == 1) {
                $this->db->where('sebagai_statistik_update', 1);
            }
        }
        $get_elemen = $this->db->get('data_statistik_strategis_ref')->result_array();

        $html = '<table class="table table-bordered table-condensed">
        		<thead>
        			<tr>
        				<th>Nama</th>
        		';
        // foreach ($p['tahun'] as $t) {
            $html .= '<th>' . $p['tahun'] . '</th>';
            $html .= '<th>Status Data</th>';
            // $html .= '<th>' . $t . '</th>';
        // }

        $html .= '</tr></thead><tbody>';


        foreach ($get_elemen as $g) {
        	$nama = '<b><i>'.$g['nama'].'</i></b>';

        	if ($g['kode1'] != "0" && $g['kode2'] != "0" && $g['kode3'] == "0") {
        		$nama = '<div style="margin-left: 40px">'.$g['nama'].'</div>';
        	} else if ($g['kode1'] != "0" && $g['kode2'] != "0" && $g['kode3'] != "0") {
                $nama = '<div style="margin-left: 80px; text-transform: uppercase; font-weight: bold">'.$g['nama'].'</div>';
            }

            $html .= '<tr><td>' . $nama . '</td>';
            
            $valu       = "";
            $stat       = "";
            $idx_elemen = $g['id'];
            $t = $p['tahun'];
            $idx_tahun  = $t;

            if (!empty($tampung_data_detil[$idx_elemen][$idx_tahun]['val'])) {
                $valu = $tampung_data_detil[$idx_elemen][$idx_tahun]['val'];
            }
            if (!empty($tampung_data_detil[$idx_elemen][$idx_tahun]['status'])) {
                $stat = $tampung_data_detil[$idx_elemen][$idx_tahun]['status'];
            }

            if (($g['kode1'] != "0" && $g['kode2'] != "0") || $g['mode_terhadap_child'] == 0) {
            	$html .= '<td><input type="text" style="text-align: right" name="data[' . $g['id'] . '][' . $t . '][val]" class="form-control input-sm" required value="' . $valu . '"></td>';
                $html .= '<td>'.form_dropdown('data['.$g['id'].']['.$t.'][status]', array("1"=>"OK","2"=>"Angka Sementara","3"=>"Angka Sangat Sementara"), $stat, 'class="form-control input-sm"').'</td>';
	        } else {
	        	$html .= '<td>&nbsp;</td><td>&nbsp;</td>';
	        }

            $html .= '</tr>';
        }

        $html .= '<tr><th colspan="3"><button type="submit" id="tbSubmit" class="btn btn-success">Simpan</button> <a href="' . base_url('index.php/statistik_strategis') . '" class="btn btn-danger">Kembali</a></th></tr></tbody></table>';

        $d['url_new']   = $url_new;
        $d['p']         = "view_form";
        $d['html_form'] = $html;
        $d['js'] = ["statistik_strategis_detil.js"];
        $d['menu_aktif'] = 3;
        $d['title']     = "Input Statistik Strategis";
        $d['bredkum']   = bredkum(array("statistik_strategis" => $d['title']), "statistik_strategis");
        $this->load->view('template', $d);
    }

    public function simpan_detil() {
        $p = $this->input->post();

        $tampung_simpan = array();
        foreach ($p['data'] as $a => $b) {
            foreach ($b as $c => $d) {
                $satu_data = array(
                    "id_ref" => $a,
                    "isi"    => $d['val'],
                    "tahun"  => $c,
                    "status_data"  => $d['status'],
                );

                $this->db->replace('data_statistik_strategis_data', $satu_data);
            }
        }
        $ret['success'] = true;
        $ret['message'] = "Data tersimpan";
        j($ret);
    }

avatar aziima27

@aziima27

5 Kontribusi 4 Poin


Jawaban Terpilih

//required dihapus menjadi

if (($g['kode1'] != "0" && $g['kode2'] != "0") || $g['mode_terhadap_child'] == 0) {
            	$html .= '<td><input type="text" style="text-align: right" name="data[' . $g['id'] . '][' . $t . '][val]" class="form-control input-sm" value="' . $valu . '"></td>';
                $html .= '<td>'.form_dropdown('data['.$g['id'].']['.$t.'][status]', array("1"=>"OK","2"=>"Angka Sementara","3"=>"Angka Sangat Sementara"), $stat, 'class="form-control input-sm"').'</td>';
avatar aziima27

@aziima27

5 Kontribusi 4 Poin

Jawaban

//required dihapus menjadi

if (($g['kode1'] != "0" && $g['kode2'] != "0") || $g['mode_terhadap_child'] == 0) {
            	$html .= '<td><input type="text" style="text-align: right" name="data[' . $g['id'] . '][' . $t . '][val]" class="form-control input-sm" value="' . $valu . '"></td>';
                $html .= '<td>'.form_dropdown('data['.$g['id'].']['.$t.'][status]', array("1"=>"OK","2"=>"Angka Sementara","3"=>"Angka Sangat Sementara"), $stat, 'class="form-control input-sm"').'</td>';
avatar aziima27

@aziima27

5 Kontribusi 4 Poin


Login untuk gabung berdiskusi