Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
Submit form dengan php tidak bisa karna penggunaan onchange dan location.replace
saya sedang membuat input data invoice, dimana ada 3 form yang akan saya simpan. no invoice, tanggal dan no po. no po ini diambil dari data po menggunakan select option, saya menggunakan onchange (onChange="pilih(this.value) untuk mengambil data po kemudian ditampilkan otomatis menggunakan tabel. dan menggunakan location.replace untuk menampilkan datanya sesuai dengan id. saat ini saya bingung untuk proses simpan semua data, yang biasanya submit otomatis karna form actionnya sudah sesuai, tapi saat diklik submit tidak mau ke submit.
1. tampilan input invoice
2. kode onchange pada select option
3. kode location.replace
4. kode form action untuk peroses semua data
2 Jawaban:
<script> function pilih(id){ location.replace("?module=form_invoice&id="+id); } </script> <!-- tampilan form add data --> <!-- Content Header (Page header) --> <section class="content-header"> <h1> <i class="fa fa-edit icon-title"></i> Input Data Invoice </h1> <ol class="breadcrumb"> <li><a href="?module=beranda"><i class="fa fa-home"></i> Beranda </a></li> <li><a href="?module=invoice"> Invoice </a></li> <li class="active"> Tambah </li> </ol> </section>
<!-- Main content --> <section class="content"> <div class="row"> <div class="col-md-12"> <div class="box box-primary"> <!-- form start -->
<div class="box-body">
<form role="form" class="form-horizontal" action="modules/invoice/proses.php?act=insert" method="POST" name="form">
<?php
// fungsi untuk membuat kode transaksi
$query_id = mysqli_query($mysqli, "SELECT RIGHT(no_invoice,8) as kode FROM tb_invoice
ORDER BY no_invoice DESC LIMIT 1")
or die('Ada kesalahan pada query tampil no_invoice : '.mysqli_error($mysqli));
$count = mysqli_num_rows($query_id);
if ($count <> 0) {
// mengambil data kode transaksi
$data_id = mysqli_fetch_assoc($query_id);
$kode = $data_id['kode']+1;
} else {
$kode = 1;
}
// buat no_invoice
$tahun = date("Y");
$buat_id = str_pad($kode, 6, "0", STR_PAD_LEFT);
$no_invoice = "INV-$tahun-$buat_id";
?>
<div class="form-group">
<label class="col-sm-2 control-label">Kode Transaksi</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="no_invoice" value="<?php echo $no_invoice; ?>" readonly required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Tanggal</label>
<div class="col-sm-5">
<input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="tanggal_invoice" autocomplete="off" value="<?php echo date("d-m-Y"); ?>" required>
</div>
</div>
<hr>
<div class="form-group">
<label class="col-sm-2 control-label">No PO</label>
<div class="col-sm-5">
<select class="chosen-select" name="id_po" id="id" onChange="pilih(this.value)" data-placeholder="-- Pilih No PO --"required>
<option value=""></option>
<?php
$id = isset($_GET['id']) ? $_GET['id'] : null;
$query = mysqli_query($mysqli, "SELECT * FROM tb_po ORDER BY id_po ASC")
or die('Ada kesalahan pada query tampil data Po: '.mysqli_error($mysqli));
while ($data= mysqli_fetch_array($query)) {?>
<option value="<?php echo $data["id_po"]?>"><?php echo $data["no_po"]?> </option>
<?php
}
?>
</select>
</div>
</div>
<table class="table table-bordered" id="resultTable" data-responsive="table">
<thead bgcolor="eeeeee" align="center">
<tr>
<th class="center">No</th>
<th class="center">No PO</th>
<th class="center">Nama Customer</th>
<th width='200px'class="center">Deksripsi Barang</th>
<th class="center">Qty</th>
<th class="center">Harga Satuan</th>
<th class="center">Total Harga</th>
<tr>
</thead>
<?php
$query=mysqli_query($mysqli,"SELECT tb_customer.kode_customer,tb_customer.nama_customer,tb_po.kode_customer,tb_po.no_po,detail_po.deskripsi_barang,detail_po.qty,detail_po.harga_satuan,detail_po.total_harga
FROM tb_po INNER JOIN detail_po on detail_po.id_po=tb_po.id_po
INNER JOIN tb_customer on tb_customer.kode_customer=tb_po.kode_customer
WHERE tb_po.id_po='$id'")
or die('Ada kesalahan pada query tampil data: '.mysqli_error($mysqli));
$no=1;
while($data=mysqli_fetch_array($query)){
?>
<tbody>
<tr>
<td class="center"><?php echo $no++;?></td>
<td class="center"><?php echo $data['no_po'];?></td>
<td class="center"><?php echo $data['nama_customer'];?></td>
<td class="center" width='200px'><?php echo $data['deskripsi_barang'];?></td>
<td class="center"><?php echo $data['qty'];?></td>
<td class="right"><?php echo $data['harga_satuan'];?></td>
<td class="right"><?php echo $data['total_harga'];?></td>
</tr>
<?php
}
?>
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th><strong style="font-size: 15px; color: #222222;">TOTAL DPP:</strong>
<th class="right"><strong style="font-size: 15px; color: #222222;">Rp.
<?php
function formatMoney($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
} else {
break;
}
}
return $number;
}
$query1 = mysqli_query($mysqli, "SELECT sum(total_harga) FROM detail_po where detail_po.id_po='$id'")
or die('Ada kesalahan pada query tampil data po: '.mysqli_error($mysqli));
while ($data= mysqli_fetch_assoc($query1)) {
$subtotal=$data['sum(total_harga)'];
echo formatMoney($subtotal, true);
$ppn=($subtotal*10)/100;
$sub_total=$subtotal+$ppn;
}
?>
</strong>
</tr>
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th><strong style="font-size: 15px; color: #222222;">PPN 10%:</strong>
<th class="right"><strong style="font-size: 15px; color: #222222;">Rp.
<?php
echo formatMoney($ppn, true);
?>
</strong>
</tr>
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th><strong style="font-size: 15px; color: #222222;">SUBTOTAL :</strong>
<th class="right"><strong style="font-size: 15px; color: #222222;">Rp.
<?php
echo formatMoney($sub_total, true);
?>
</strong>
</tr>
</tbody>
</table>
<input type="hidden" name="subtotal" value="<?php echo $subtotal; ?>">
<input type="hidden" name="ppn" value="<?php echo $ppn; ?>">
<input type="hidden" name="sub_total" value="<?php echo $sub_total; ?>">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary btn-submit" name="simpan" value="Simpan">
<a href="?module=invoice" class="btn btn-default btn-reset">Batal</a>
</div>
</div><!-- /.box footer -->
</form>
</div><!-- /.box -->
</div><!--/.col -->
</div> <!-- /.row -->
</div> <!-- /.row -->
</div> <!-- /.row -->
</section><!-- /.content -->