TUGAS PHP PEMROGRAMAN WEB
- Tugas terdiri dari dua halaman php, untuk penentuan nilai pada list menu/combo box HARUS memakai KODE PHP
- Proses input akan error jika tidak sesuai dengan kriterianya (dideteksi dengan javascript sebelum halaman dikirimkan)
PRPOGRAM KIRIM.PHP
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Kirim</title> <style> form { max-width: 500px; margin: auto; } fieldset { border-radius: 5px; padding: 20px; margin-bottom: 20px; } .input-group { display: flex; justify-content: space-between; margin-bottom: 15px; } .input-group > input, .input-group > select, .input-radio { width: 100%; } .label { width: 150px; } input, select { padding: 7px; } .button-group { display: flex; justify-content: space-around; } </style></head><body> <form id="form" action="terima.php?nama=&status=&telp=" method="post"> <fieldset> <legend>Identitas</legend> <div class="input-group"> <label class="label" for="nama">Nama</label> <input type="text" id="nama" required> </div> <div class="input-group"> <label class="label">Status</label> <div class="input-radio"> <input type="radio" class="status" id="member" value="Member" name="status" onclick="handleStatus('Member')" checked> <label for="member">Member</label> <input type="radio" class="status" id="umum" value="Umum" name="status" onclick="handleStatus('Umum')"> <label for="umum">Umum</label> </div> </div> <div class="input-group"> <label class="label" for="telp">Telepon</label> <input type="text" id="telp" required> </div> </fieldset> <fieldset> <legend>Transaksi Buku</legend> <div class="input-group"> <label class="label" for="item_buku">Item</label> <input type="text" id="item_buku" name="item_buku" required> </div> <div class="input-group"> <label class="label" for="jumlah_buku">Jumlah (pcs)</label> <select name="jumlah_buku" id="jumlah_buku"> <?php for($i = 1; $i <= 150; $i++) : ?> <option value="<?= $i ?>"><?= $i ?></option> <?php endfor; ?> </select> </div> <div class="input-group"> <label class="label" for="harga_buku">Harga (Rp)</label> <input type="number" id="harga_buku" name="harga_buku" > </div> </fieldset> <fieldset> <legend>Transaksi Lainnya</legend> <div class="input-group"> <label class="label" for="item_lainnya">Item</label> <select name="item_lainnya" id="item_lainnya"> <option value="ATM">ATM</option> <option value="Accessories">Accessories</option> <option value="PAPER">PAPER</option> </select> </div> <div class="input-group"> <label class="label" for="jumlah_lainnya">Jumlah (pcs)</label> <select name="jumlah_lainnya" id="jumlah_lainnya"> <?php for($i = 1; $i <= 150; $i++) : ?> <option value="<?= $i ?>"><?= $i ?></option> <?php endfor; ?> </select> </div> <div class="input-group"> <label class="label" for="harga_lainnya">Harga (Rp)</label> <input type="number" id="harga_lainnya" name="harga_lainnya" > </div> </fieldset> <fieldset> <legend>Aksi</legend> <div class="button-group"> <button type="reset">Clear</button> <button type="reset">Cancel</button> <button type="submit">Submit</button> </div> </fieldset> </form> <script> let status = 'Member' const nama = document.getElementById('nama') const handleStatus = (value) => { status = value } const telp = document.getElementById('telp') const form = document.getElementById('form')
nama.addEventListener('change', () => { fieldNama = nama.value }) telp.addEventListener('change', () => { fieldTelp = telp.value }) form.addEventListener('submit', () => { action = 'terima.php?nama='+fieldNama+'&status='+status+'&telp='+fieldTelp form.setAttribute('action', action) }) </script></body></html>
PROGRAM TERIMA.PHP (REKAP)
<?php if(count($_GET) == 0 || count($_POST) == 0) { header('Location: kirim.php'); } $data_get = $_GET; $data_post = $_POST; $harga_buku = $data_post['jumlah_buku'] * $data_post['harga_buku']; $harga_lainnya = $data_post['jumlah_lainnya'] * $data_post['harga_lainnya'];
if($data_post['jumlah_buku'] > '30') { $diskon_buku = '3%'; $total_harga_buku = $harga_buku - (($harga_buku) * 3 / 100); } elseif ($data_post['jumlah_buku'] > '10') { $total_harga_buku = $harga_buku - (($harga_buku) * 2 / 100); $diskon_buku = '2%'; } else { $total_harga_buku = $harga_buku; $diskon_buku = '0%'; }
if($data_post['item_lainnya'] == 'ATM') { $diskon_lainnya = '10%'; $total_harga_lainnya = $harga_lainnya - (($harga_lainnya) * 10 / 100); } elseif ($data_post['item_lainnya'] == 'PAPER') { $diskon_lainnya = '2.5%'; $total_harga_lainnya = $harga_lainnya - (($harga_lainnya) * 2.5 / 100); } else { $diskon_lainnya = '20%'; $total_harga_lainnya = $harga_lainnya - (($harga_lainnya) * 20 / 100); }
$total_bayar = $total_harga_buku + $total_harga_lainnya; if ($data_get['status'] == 'Member') { $diskon_final = '10%'; $grand_total = $total_bayar - (($total_bayar) * 10 / 100); } else if ($data_get['status'] == 'Umum') { $diskon_final = '2%'; $grand_total = $total_bayar - (($total_bayar) * 2 / 100); } else { $diskon_final = '15%'; $grand_total = $total_bayar - (($total_bayar) * 15 / 100); }?>
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Terima</title> <style> .mb-10 { margin-bottom: 10px; } .container { max-width: 500px; margin: auto; } fieldset { border-radius: 5px; padding: 20px; margin-bottom: 20px; } .input-group { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; } .label { width: 150px; } span { padding: 7px; border: 1px solid gray; border-radius: 5px; width: 100%; } legend { font-weight: bold; } .button-group button { width: 100%; padding: 5px; } </style></head><body> <div class="container"> <fieldset> <legend>| Identitas |</legend> <div class="input-group"> <label class="label">Nama</label> <span><?= $data_get['nama'] ?></span> </div> <div class="input-group"> <label class="label">Status</label> <span><?= $data_get['status'] ?></span> </div> <div class="input-group"> <label class="label">Telepon</label> <span><?= $data_get['telp'] ?></span> </div> </fieldset> <fieldset> <legend>| Rekapitulasi |</legend> <div class="input-group"> <label class="label">Item</label> <span><?= $data_post['item_buku'] ?></span> </div> <div class="input-group"> <label class="label">Jumlah</label> <span><?= $data_post['jumlah_buku'] ?></span> </div> <div class="input-group"> <label class="label">Harga (Rp)</label> <span><?= $data_post['harga_buku'] ?></span> </div> <div class="input-group"> <label class="label">Total (Rp)</label> <span><?= $total_harga_buku. ' (Diskon. '.$diskon_buku.')' ?></span> </div> <hr> <div class="input-group"> <label class="label">Item</label> <span><?= $data_post['item_lainnya'] ?></span> </div> <div class="input-group"> <label class="label">Jumlah</label> <span><?= $data_post['jumlah_lainnya'] ?></span> </div> <div class="input-group"> <label class="label">Harga (Rp)</label> <span><?= $data_post['harga_lainnya'] ?></span> </div> <div class="input-group"> <label class="label">Total (Rp)</label> <span><?= $total_harga_lainnya. ' (Diskon. '.$diskon_lainnya.')' ?></span> </div> <hr> <div class="input-group"> <label class="label"><b>Grand Total</b> (Rp)</label> <span><?= $grand_total. ' (Diskon Status. '.$diskon_final.')' ?></span> </div> </fieldset> <fieldset class="mb-10"> <legend>Aksi</legend> <div class="button-group"> <button type="button">OK</button> </div> </fieldset> </div></body></html>
Kategori
Blogroll
- Masih Kosong