Postingan lainnya
Update data form modal (solved)
saya mau update data dengan form modal tapi pas diklik, data yang di pilih nggak keambil
controller
public function update(){
$id_p = $this->input->post('id_p');
$data = [
'kd_penyakit' => $this->input->post('kd_penyakit',true),
'nama' => $this->input->post('nama',true),
'keterangan' => $this->input->post('keterangan',true)
];
$this->m_penyakit->updatePenyakit($data,$id_p);
redirect('penyakit');
}
model
public function updatePenyakit($data,$id_p){
$this->db->where('id_p',$id_p);
$this->db->update('tb_penyakit',$data);
}
view
<tbody>
<?php $no =1; ?>
<?php foreach ($penyakit as $data) : ?>
<td><?= $no++ ?></td>
<td><?= $data['kd_penyakit'] ?></td>
<td><?= $data['nama'] ?></td>
<td><?= $data['keterangan'] ?></td>
<td>
<a href="javascript:;"
data-id_p="<?= $data['id_p'] ?>"
data-kd_penyakit="<?= $data['kd_penyakit'] ?>"
data-nama="<?= $data['nama'] ?>"
data-keterangan="<?= $data['keterangan'] ?>"
data-toggle="modal" data-target="#edit-data">
<button data-toggle="modal" data-target="#update-data" class="btn btn-info">Ubah</button>
</a>
<a href="#" class="btn btn-danger">Hapus</a>
</td>
</tr>
<?php endforeach ?>
</tbody>
<!-- Modal Update -->
<div class="modal fade" id="update-data" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
<div class="modal-dialog modal- modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="modal-title-default">Update Data Penyakit</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="<?=base_url('penyakit/update')?>" method="post" enctype="multipart/form-data" role="form">
<div class="modal-body p-0">
<div class="card bg-secondary shadow border-0">
<div class="card-header bg-transparent pb-5">
<div class="form-group mb-3">
<input type="hidden" id="id_p" name="id_p">
<h4>Kode Penyakit<h4>
<div class="input-group input-group-alternative">
<input class="form-control" id="kd_penyakit" name="kd_penyakit" placeholder="Masukkan Kode Penyakit" type="text">
</div>
</div>
<div class="form-group mb-3">
<h4>Nama Penyakit<h4>
<div class="input-group input-group-alternative">
<input class="form-control" id="nama" name="nama" placeholder="Masukkan Nama Penyakit" type="text">
</div>
</div>
<div class="form-group mb-3">
<h4>Keterangan<h4>
<div class="input-group input-group-alternative">
<textarea class="form-control" rows="5" id="keterangan" name="keterangan" placeholder="Masukkan Keterangan" type="text"></textarea>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-link ml-auto" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
<!-- End of Modal Update -->
<script>
$(document).ready(function(){
$('#edit-data').on('show.bs.modal', function (event) {
var div = $(event.relatedTarget)
var modal = $(this)
modal.find('#id_p').attr("value",div.data('id_p'));
modal.find('#kd_penyakit').attr("value",div.data('kd_penyakit'));
modal.find('#nama').attr("value",div.data('nama'));
modal.find('#keterangan').html(div.data('keterangan'));
});
});
</script>
0
1 Jawaban:
Coba Controller nya ganti sama yang ini
<pre> public function update(Request $request, $id) { $rule = [ 'kd_penyakit' => 'required', 'nama' => 'required', 'keterangan' =>'required' ]; $this->validate($request, $rule);
$input = $request-&gt;all();
$produk = \App\updatepenyakit::find($id);
$produk-&gt;kd_penyakit = $input['kd_penyakit'];
$produk-&gt;nama = $input['nama'];
$produk-&gt;keterangan= $input['keterangan'];
$produk-&gt;update();
return redirect ('/penyakit');
}
</pre>
Apa wajib menggunakan modal atau engga?
Jangan lupa di controller nya pake use/App/updatepenyakit
0
Tanggapan
lupa ngasih tahu kalo saya pakai ci