Postingan lainnya
Kenapa ketika akan verifikasi button dalam modal tidak ada action stuck di modal
Saya sedang membuat Verifikasi untuk pengubahan status dengan modal bootstrap tetapi ketika modal muncul dan saya pilih opsi lalu klik button verifikasi tidak ada action apapun dan stuck di modal kenapa ya?
kode saya seperti ini
<?php
session_start();
include 'header.php';
include 'menu.php';
?>
<main id="main" class="main">
<div class="pagetitle">
<nav>
<ol class="breadcrumb">
</ol>
</nav>
</div><!-- End Page Title --> <br>
<!-- Recent Sales -->
<div class="col-12">
<div class="card recent-sales overflow-auto">
<div class="card-body">
<h5 class="card-title">Community Complaints Data</span></h5>
<table class="table table-borderless datatable">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Date</th>
<th scope="col">Name</th>
<th scope="col">NIK</th>
<th scope="col">Contents of the report</th>
<th scope="col">Picture</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
include '../config.php';
$no = 1;
if (isset($_POST['submit'])) {
$search = $_POST['search'];
$data = mysqli_query($koneksi, "SELECT p.*, m.nama FROM pengaduan p JOIN masyarakat m ON p.nik = m.nik WHERE p.tgl_pengaduan LIKE '%$search%' OR m.nama LIKE '%$search%' OR p.isi_laporan LIKE '%$search%' OR p.status LIKE '%$search%'");
} else {
$data = mysqli_query($koneksi, "SELECT p.*, m.nama FROM pengaduan p JOIN masyarakat m ON p.nik = m.nik");
}
while ($d = mysqli_fetch_array($data)) {
?>
<tr>
<th scope="row"><?php echo $no++; ?> </th>
<td><?php echo $d['tgl_pengaduan']; ?></td>
<td><?php echo $d['nama']; ?></td>
<td><?php echo $d['nik']; ?></td>
<td><?php echo $d['isi_laporan']; ?></td>
<td><img src="../img/<?php echo $d['foto']; ?>" width="100" height="100"></td>
<td>
<?php
if ($d['status'] == 'proses') {
echo "<span class='badge bg-warning'>Process</span>";
} elseif ($d['status'] == 'selesai') {
echo "<span class='badge bg-success'>Finished</span>";
} else {
echo "<span class='badge bg-danger'>Waiting</span>";
}
?>
</td>
<td>
<!-- Verifikasi -->
<?php
if ($d['status'] != 'selesai') {
?>
<a href="#" class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#verifikasi<?php echo $d['id_pengaduan'] ?>"> <i class="bx bxs-check-circle"></i></a>
<!-- Modal Verifikasi-->
<div class="modal fade" id="verifikasi<?php echo $d['id_pengaduan'] ?>" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Verification Complaint Data</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="" method="POST">
<input type="hidden" name="id_pengaduan" class="form-control"
value="<?php echo $d['id_pengaduan'] ?>">
<div class="row mb-3">
<label class="col-md-4">Status</label>
<div class="col-md-8">
<select class="form-control" name="status">
<option value="">-- Select Status --</option>
<option value="proses">Process</option>
<option value="0">Reject</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" name="kirim" class="btn btn-primary">Verification</button>
</div>
</form>
</div>
</div>
</div>
<?php
}
if (isset($_POST['kirim'])){
$id_pengaduan = $_POST['id_pengaduan'];
$status = $_POST['status'];
$query = mysqli_query($koneksi, "UPDATE pengaduan SET status='$status' WHERE id_pengaduan='$id_pengaduan'");
echo "<script>
alert('data berhasil diupdate');
window.location='tampildata.php';
</script>";
}
?>
<!-- Tanggapan -->
<?php
if ($d['status'] != 'selesai') {
?>
<a href="#" class="btn btn-success" data-bs-toggle="modal"
data-bs-target="#tanggapan<?php echo $d['id_pengaduan'] ?>">
<i class="bi bi-card-text"></i>
</a>
<!-- Modal Tanggapan-->
<div class="modal fade" id="tanggapan<?php echo $d['id_pengaduan'] ?>" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Response</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="" method="POST">
<div class="row mb-3">
<div class="col-md-4">
<label>Date</label>
</div>
<div class="col-md-8">
<input type="text" name="tgl_pengaduan" class="form-control"
value="<?php echo $d['tgl_pengaduan']?>" readonly>
</div>
</div>
<div class="row mb-3">
<div class="col-md-4">
<label>Contents of the report</label>
</div>
<div class="col-md-8">
<textarea name="isi_laporan" class="form-control"
readonly><?php echo $d['isi_laporan']?></textarea>
</div>
</div>
<div class="row mb-3">
<div class="col-md-4">
<label>Picture</label>
</div>
<div class="col-md-8">
<img src="../img/<?php echo $d['foto']; ?>" width="80" height="80">
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-4">
<label>Response</label>
</div>
<div class="col-md-8">
<textarea name="tanggapan" class="form-control" pattern="[^\d]+" required></textarea>
</div>
</div>
<input type="hidden" name="id_pengaduan" value="<?php echo $d['id_pengaduan'] ?>">
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" name="kirim" class="btn btn-primary">Response</button>
</div>
</form>
<?php
if (isset($_POST['kirim'])){
$id_pengaduan = $_POST['id_pengaduan'];
$id_petugas = $_SESSION['id_petugas'];
$tanggal = date("Y-m-d");
$tanggapan = $_POST['tanggapan'];
// Update status pengaduan menjadi "selesai"
$query = mysqli_query($koneksi, "UPDATE pengaduan SET status='selesai' WHERE id_pengaduan='$id_pengaduan'");
// Insert tanggapan ke dalam tabel tanggapan
if ($tanggapan != NULL) {
$insert = mysqli_query($koneksi, "INSERT INTO tanggapan VALUES(NULL, '$id_pengaduan', '$tanggal', '$tanggapan', '$id_petugas')");
}
echo "<script>
alert('data berhasil diupdate');
window.location='tampildata.php';
</script>";
}
?>
</div>
</div>
</div>
<?php } ?>
<!-- Hapus -->
<button type="button" class="btn btn-danger" data-bs-toggle="modal"
data-bs-target="#hapusModal<?php echo $d['id_pengaduan'] ?>"> <i class="bi bi-trash"></i>
</button>
<!-- Modal -->
<div class="modal fade" id="hapusModal<?php echo $d['id_pengaduan'] ?>" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="hapusModal<?php echo $d['id_pengaduan'] ?>">Delete Complaint Data
</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="proseshapus.php" method="POST">
<input type="hidden" name="id_pengaduan" value="<?php echo $d['id_pengaduan'] ?>">
<div class="modal-body">
Are you sure wanna delete complaint data ?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" name="hapus_" value="hapus" class="btn btn-danger">Delete</button>
</div>
</form>
</div>
</div>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div><!-- End Recent Sales -->
</main><!-- End #main -->
<script>
function hapus(id) {
if (confirm("Apakah Anda yakin ingin menghapus data ini?")) {
window.location.href = "hapus.php?id=" + id;
}
}
</script>
<?php
include 'footer.php';
?>
Terimakasih...
1 Jawaban:
<div>Alasan mengapa tidak ada tindakan ketika kamu memilih opsi dan mengklik tombol verifikasi adalah karena kamu tidak mengirimkan formulir. Kamu perlu menambahkan tombol submit
ke dalam formulir dan kemudian memanggil metode submit()
pada formulir ketika pengguna mengklik tombol tersebut. Contohnya:<br><br></div><pre>html <form action="" method="POST"> <input type="hidden" name="id_pengaduan" class="form-control" value="<?php echo $d['id_pengaduan'] ?>"> <div class="row mb-3"> <label class="col-md-4">Status</label> <div class="col-md-8"> <select class="form-control" name="status"> <option value="">-- Pilih Status --</option> <option value="proses">Proses</option> <option value="0">Tolak</option> </select> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button> <button type="submit" name="kirim" class="btn btn-primary">Verifikasi</button> </div> </form>
</pre><div><br>Kamu juga dapat menggunakan peristiwa onsubmit
untuk mengirimkan formulir ketika pengguna mengklik tombol. Contohnya:<br><br></div><pre>```html
<form action="" method="POST" onsubmit="return confirm('Apakah kamu yakin?')">
<input type="hidden" name="id_pengaduan" class="form-control"
value="<?php echo $d['id_pengaduan'] ?>">
<div class="row mb-3">
<label class="col-md-4">Status</label>
<div class="col-md-8">
<select class="form-control" name="status">
<option value="">-- Pilih Status --</option>
<option value="proses">Proses</option>
<option value="0">Tolak</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<button type="submit" name="kirim" class="btn btn-primary">Verifikasi</button>
</div>
</form>