Tugas Pertemuan 7 Web Programming II

 1. Ada sebuah toko sepatu yang ingin dibuatkan program untuk menghitung otomatis dari transaksi penjualan sepatunya yang mana harga sepatu ditentukan berdasarkan merk dari sepatu tersebut. 

2. Buatlah tampilan form input transaksi di point 1 meliputi input nama pembeli menggunakan text, no hp menggunakan text, merk sepatu berupa pilihan combo/select berisi Nike, Adidas, Kickers, Eiger, Bucherri. Masing-masing memiliki harga sesuai urutan yaitu 375000, 300000, 250000, 275000, 400000., ukuran sepatu berupa combo/select juga berisi pilihan ukuran dari no 32 s/d nomor 44. Dan terakhir terdapat tombol submit untuk memproses inputan tersebut. 

3. Buatlah sebuah controller dan model untuk memproses inputan form sehingga hasilnya di tampilkan ke file view yang berisi hasil dari proses submit dari form input. 

4. Pada tampilan hasil, buatlah link untuk kembali menuju file input form pada point 2

Script Pengerjaan untuk Toko Sepatu

1. tokosepatu.php

<?php
 class tokosepatu extends CI_Controller
 {
    public function index()
    {
        $this->load->view('view-form-tokosepatu');
    }

    public function cetak()
    {
        $this->form_validation->set_rules(
            'nama',
            'nama',
            'required|min_length[3]',
            [
                'required' => 'Nama Harus Di isi',
                'min_length' => 'Nama terlalu pendek'
            ]
        
        );
        
        $this->form_validation->set_rules(
            'no',
            'no hp',
            'required|min_length[11]',
            [
                'required' => 'No HP Harus diisi',
                'min_length' => 'No HP terlalu pendek'
            ]
        
        );

        if ($this->form_validation->run() != true) {
            $this->load->view('view-form-tokosepatu');
        } else {

            $data = [
                'nama' => $this->input->post('nama'),
                'no' => $this->input->post('no'),
                'merk' => $this->input->post('merk'),
                'size' => $this->input->post('size'),
                'harga' => $this->input->post('harga'),
            ];

            if ($this->input->post('merk') == 'Nike') {
                $data['harga'] = 375000;
            } elseif ($this->input->post('merk') == 'Adidas') {
                $data['harga'] = 300000;
            } elseif ($this->input->post('merk') == 'Kickers') {
                $data['harga'] = 250000;
            } elseif ($this->input->post('merk') == 'Eiger') {
                $data['harga'] = 275000;
            } elseif ($this->input->post('merk') == 'Bucherri') {
                $data['harga'] = 400000;
            }

            $this->load->view('view-data-tokosepatu' , $data);
        }
    }
}

2. view-data-tokosepatu.php

<!DOCTYPE html>
<html>
<head>
    <title>REKAP TRANSAKSI</title>
</head>

<body>
    <center>
        <table bgcolor="green">
            <tr>
                <th colspan="5">
                    <h3>TOKO SEPATU PELANGI</h3>
                    <hr>
                </th>
            </tr>
            <tr>
                <td>NAMA PEMBELI</td>
                <td>:</td>
                <td><?= $nama ?></td>
            </tr>
            <tr>
                <td></td>
            </tr>
            <tr>
                <td>NO HP</td>
                <td>:</td>
                <td><?= $no ?></td>
            </tr>
            <tr>
                <td></td>
            </tr>
            <tr>
                <td>MERK SEPATU</td>
                <td>:</td>
                <td><?= $merk ?></td>
            </tr>
            <tr>
                <td></td>
            </tr>
            <tr>
                <td>UKURAN SEPATU</td>
                <td>:</td>
                <td><?= $size ?></td>
            </tr>
            <tr>
                <td></td>
            </tr>
            <tr>
                <td>HARGA</td>
                <td>:</td>
                <td>Rp. <?= $harga ?></td>
            </tr>
            <tr>
                <td colspan="3">
                    <hr>
                </td>
            </tr>
        </table>
        <p><button><a href="<?php echo base_url() . 'index.php/tokosepatu' ?>">KEMBALI</a></button></p>
    </center>
</body>
</html>

3. view-form-tokosepatu.php

<html>

<head>
    <title>TOKO SEPATU</title>

    <style>
        .error1 {
            colorblack;
        }
    </style>
</head>

<body>
    <center>
        <form action="<?= base_url('tokosepatu/cetak'); ?>" method="post">
            <table bgcolor='turquoise' width="200px">
                <tr>
                    <th>
                        <h3>TOKO SEPATU PELANGI</h3>
                        <hr>
                    </th>
                </tr>

                <tr>
                    <td colspan="5"><input type="text" name="nama" id="nama" placeholder="Nama"></td>
                </tr>
                <tr>
                    <td class="error1"><b> <?= form_error('nama'); ?></b></td>
                </tr>
                <tr>
                    <td> <input type="text" name='no' id='no' placeholder="No HP"></td>
                </tr>
                <tr>
                    <td class="error1"><b> <?= form_error('no'); ?></b></td>
                </tr>
                <tr>
                    <td>
                        <select name="merk" id="merk">
                            <option value="">--PILIH MERK SEPATU--</option>
                            <option value="Nike">NIKE</option>
                            <option value="Adidas">ADIDAS</option>
                            <option value="Kickers">KICKERS</option>
                            <option value="Eiger">EIGER</option>
                            <option value="Bucherri">BUCHERRI</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="error1"><b> <?= form_error('merk'); ?></b></td>
                </tr>
                <tr>
                    <td><b>UKURAN SEPATU :</b></td>
                </tr>
                <tr>
                    <td>
                        <input type="radio" name="size" value="32">32
                        <input type="radio" name="size" value="33">33
                        <input type="radio" name="size" value="34">34
                        <input type="radio" name="size" value="35">35
                    </td>
                </tr>
                    <td></td>
                <tr>
                    <td>
                        <input type="radio" name="size" value="36">36
                        <input type="radio" name="size" value="37">37
                        <input type="radio" name="size" value="38">38
                        <input type="radio" name="size" value="39">39
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="radio" name="size" value="40">40
                        <input type="radio" name="size" value="41">41
                        <input type="radio" name="size" value="42">42
                        <input type="radio" name="size" value="43">43
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="radio" name="size" value="44">44
                    </td>
                </tr>
                <tr>
                    <td class="error1"><b> <?= form_error('size'); ?></b></td>
                </tr>
                <tr>
                    <td align="center" colspan="3">
                        <input type="submit" name="KONFIRMASI">
                        <input type="reset" name="BATAL">
                    </td>
                </tr>
            </table>
    </center>
</body>

</html>


Komentar

Postingan populer dari blog ini

TUGAS WEB PROGRAMMING PERTEMUAN 9

Web Programminng 2 Pertemuan 10 Membuat Form Registrasi User