Assallmualaikm mas robby
saya punya kasus seperti ini
di view tampilannya ,, menggunakan select dan form input biasa
nahh bagaimana supaya ID yang di select(untuk menampilkan datanya terlebih dahulu sesuai id) bisa ikut ke save pada saat klik tombol save, berikut gambarnya dan scriptnya
script controllers
function tampil_save(){
cek_session_admin();
$id = $this->uri->segment(3);
if (isset($_POST['submit'])){
$this->model_main->updatedata();
$this->session->set_flashdata("pesan", "<div class=\"col-md-12\"><div class=\"alert alert-success\" id=\"alert\">Data berhasil diupdate!! </div></div>");
redirect('Keuangan/tampil_save');
}else{
$data['rows'] = $this->model_main->tampil_save($id)->row_array();
$data['agentcabang'] = $this->model_main->joincabang();
$this->session->set_flashdata("pesan", "<div class=\"col-md-12\"><div class=\"alert alert-danger\" id=\"alert\">Gagal!!</div></div>");
$this->template->load('Cpanelweb/template','Cpanelweb/mod_cabang/view_tampil_save',$data);
}
}
view view_tampil_save.php
<?php
echo "<div class='col-md-12'>
<div class='box box-info'>
<div class='box-header with-border'>
<h3 class='box-title'>Data pesanan</h3>
</div>
<div class='box-body'>";
$attributes = array('class'=>'form-horizontal','role'=>'form'); echo form_open_multipart('Keuangan/tampil_save',$attributes);
echo "<div class='col-md-12'>
<table class='table table-condensed table-bordered'>
<tbody>
<input type='hidden' name='id' value='$rows[id_]'>
<tr>
<th width='120px' scope='row'>Nama Paket </th> <th>:</th> <th>$rows[nama_paket]</th>
</tr>
<tr>
<th width='120px' scope='row'>Program hari </th> <th>:</th> <th>$rows[program_hari]</th>
</tr>
<tr>
<th width='250px' scope='row'>Keberangkatan tanggal </th> <th>:</th> <th>$rows[keberangkatan_tanggal]</th>
</tr>
</tbody>
</table>
</div>
</div>
<div class='col-md-12'>
<table class='table table-condensed table-bordered'>
<tbody>
<input type='hidden' name='id' value='$rows[id_]'>
<tr>
<th width='120px' scope='row'>Nama Depan</th>
<td><input type='text' name='nama_depan' class='form-control'></td>
<th width='120px' scope='row'>Nama Tengah</th>
<td><input type='text' name='nama_tengah' class='form-control'></td>
</tr>
<tr>
<th width='120px' scope='row'>Nama Belakang</th>
<td><input type='text' name='nama_belakang' class='form-control'></td>
<th width='120px' scope='row'>Alamat</th>
<td><textarea type='text' name='alamat' class='form-control'></textarea></td>
</tr>
<tr>
<th width='120px' scope='row'>Tanggal lahir</th>
<td><input type='text' name='tgl_lahir' id='tgl_lahir' class='form-control'></td>
<th width='120px' scope='row'>Tempat lahir lahir</th>
<td><input type='text' name='tempat_lahir' class='form-control'></td>
</tr>
<tr>
<th width='120px' scope='row'>No HP</th>
<td><input type='text' name='no_hp' class='form-control'></td>
<th width='120px' scope='row'>No tlp</th>
<td><input type='text' name='no_tlp' class='form-control'></td>
</tr>
<tr>
<th width='120px' scope='row'>Email</th>
<td><input type='email' name='email' class='form-control'></td>
<th width='120px' scope='row'>Virtual account</th>
<td><input type='text' name='no_virtual_account' class='form-control'></td>
</tr>
<tr>
<th width='120px' scope='row'>Tgl issued</th>
<td><input type='email' name='tgl_issued' id='tgl_issued' class='form-control'></td>
<th width='120px' scope='row'>Tgl expired</th>
<td><input type='text' name='tgl_expired' id='tgl_expired' class='form-control'></td>
</tr>
<tr>
<th width='120px' scope='row'>Tempat imigrasi</th>
<td><input type='text' name='tempat_imigrasi' id='tgl_issued' class='form-control'></td>
<th width='120px' scope='row'>Marketing agent</th>
<td>
<select name='marketing_agent' class='form-control'>
<option value='0'>--pilih refrensi marketing --</option>";
foreach ($agentcabang->result_array() as $row){
if ($rows['id_agent'] == $row['id_agent']){
echo "<option value='$row[id_agent]' selected>$row[nama_agent_cabang]</option>";
}else{
echo "<option value='$row[id_agent]'>$row[nama_agent_cabang]</option>";
}
}
echo "</td></tr>
</tbody>
</table>
</div>
<div class='box-footer'>
<button type='submit' name='submit' class='btn btn-primary'>Save</button>
<a href='../listbranch'><button type='button' class='btn btn-default pull-right'>Cancel</button></a>
</div>
</div>";
//mODEL
function updatedata(){
$datadb = array('id_'=>$this->db->escape(trim($this->input->post('id'))), 'nama_depan'=>$this->db->escape_str(trim($this->input->post('nama_depan'))), 'nama_tengah'=>$this->db->escape_str(trim($this->input->post('nama_tengah'))), 'nama_belakang'=>$this->db->escape_str(trim($this->input->post('nama_belakang'))), 'alamat'=>$this->db->escape_str(trim($this->input->post('alamat'))), 'tgl_lahir'=>$this->db->escape_str(trim($this->input->post('tgl_lahir'))), 'tempat_lahir'=>$this->db->escape_str(trim($this->input->post('tempat_lahir'))), 'email'=>$this->db->escape_str(trim($this->input->post('email'))), 'no_hp'=>$this->db->escape_str(trim($this->input->post('no_hp'))), 'no_telp'=>$this->db->escape_str(trim($this->input->post('no_telp'))), 'no_virtual_account'=>$this->db->escape_str(trim($this->input->post('no_virtual_account'))) //'id'=>$this->db->escape_str($this->input->post('nama_bank'))
);
$this->db->where('id_cus',$this->input->post('id'));
$this->db->update('tbl_customer',$datadb);
}