i had form that is add some fields via jquery when i click " add new " button it will update a dom , with input fields . Input fields are using a array as a name , when i click submit button , values did not post to php, only static form values are posted but not dynamically generated input values .
My fiddle is http://jsfiddle.net/4L9Rc/
It will demonstrate clearly how is my form working .
HTML
<div class="row">
<div class="col-md-12">
<form method="POST" action="http://fabtech.com/invoices/create" accept-charset="UTF-8" role="form" class="form-horizontal re-form form-inv"><input name="_token" type="hidden" value="aLngVzB1UIlY6cEedbAh55tirXGGkYJl78BL0CRN"> <legend>Invoice Details</legend>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Invoice No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter invoice no" class="form-control" name="inv_no" value=""">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Invoice date</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control date-pic" name="inv_date" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Customer</label>
<div class="col-md-7">
<select class="form-control" name="inv_customer">
<option value="">- Select Customer -</option>
<option value="suresh">suresh</option>
<option value="ABC210">ABC210</option>
<option value="QWERTy123DF">QWERTy123DF</option>
<option value="CUS002">CUS002</option>
<option value="CUS0023">CUS0023</option>
<option value="CUS003">CUS003</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control" name="po_no" value="">
</div> </div>
<div class="form-group">
<label class="col-md-4 control-label">PO date</label>
<div class="col-md-7">
<input type="text" placeholder="DD/MM/YYY" class="form-control date-pic" name="po_date" value="">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Vendor code</label>
<div class="col-md-7">
<input type="text" placeholder="Enter Vendor Code" class="form-control" name="vendor_code" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">75% abatement value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control sf" name="sf">
</div>
<div class="col-md-6 sfbox" style="display:none">
<input type="text" class="form-control sfboxval" readonly="">
</div> </div>
<div class="form-group">
<label class="col-md-4 control-label">25% Taxable Value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control tf" name="tf">
</div>
<div class="col-md-6 tfbox" style="display:none" >
<input type="text" class="form-control tfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Tax in %</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control tax" name="tax" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Grand Total</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control grandtotal" readonly="" name="grand_total">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<legend>Particulars
<a class="btn btn-xs btn-success" id="apm"><i class="icon-plus"></i> Add new</a>
</legend>
<table id="apmr" width="69%" class="table table-striped table-bordered table-hover invoice">
<thead>
<tr>
<th width="3%">SL No</th>
<th width="25%">Description</th>
<th width="8%">Unit</th>
<th width="8%">Qty</th>
<th width="10%">Unit rate</th>
<th width="9%"> Amount</th>
</tr>
</thead>
<tbody class="roo">
<tr>
<td valign="center"> 1 </td>
<td class="tr_nt"><input type="text" name="parti[1][desc]" class="part"></td>
<td class="tr_nt"><input type="text" name="parti[1][unit]" class="part"></td>
<td class="tr_qty into"><input type="text" name="parti[1][qty]" class="part qty"></td>
<td class="tr_urate into"><input type="text" name="parti[1][urate]" class="part ur"></td>
<td class="tr_amt"><input type="text" name="parti[1][amount]" readonly="" class="part tot"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
</td>
<td colspan="2">
Particular's Total: Rs <span class="parttotal"></span>
</td>
</tr>
</tfoot>
</table>
<p style="text-align: center;padding-top: 5px;"><input name="submit" class="btn-lg btn-primary" type="submit" value="View Invoice"></p>
</form> </div>
</div>
</div>
</div>
Javascript
//invoice particulars
var val;
$("#apm").click(function(event) {
//event.preventDefault();
//var preData = $("#apmr tr:last").html();
//console.log(preData);
//
//$("#apmr tr:last").after('<tr>' + preData + '</tr>');
var lasttd = $('.roo tr:last td:first').text();
val = parseInt(lasttd) + 1;
$(".roo tr:last").after(' <tr> <td valign="center"> ' + val + ' </td> <td class="tr_nt"><input type="text" name="parti[' + val + '][desc]" class="part"></td> <td class="tr_nt"><input type="text" name="parti[' + val + '][unit]" class="part"></td> <td class="tr_qty into"><input type="text" name="parti[' + val + '][qty]" class="part qty"></td> <td class="tr_urate into"><input type="text" name="parti[' + val + '][urate]" class="part ur"></td> <td class="tr_amt"><input type="text" name="parti[' + val + '][amount]" readonly class="part tot" ></td></tr>');
// val = val + 1;
return false;
})
var gt;
$("table.invoice").on("change", '.qty, .ur', function(event) {
calculateRow($(this).closest("tr"));
calculateTotal();
});
function calculateRow(row) {
var price = +row.find('.qty').val();
var qty = +row.find('.ur').val();
row.find('.tot').val((price * qty).toFixed(2));
}
function calculateTotal() {
var Total = 0;
$("table.invoice").find('.tot').each(function() {
Total += +$(this).val();
});
$(".parttotal").text(Total.toFixed(2));
calgrand();
}
$(".re-form").on('change', '.tax,.tf,.sf', function(event) {
calgrand();
})
function calgrand() {
var taxVal = $('.tax').val();
var parVal = $(".parttotal").text();
var result = parVal - taxVal * parVal / 100;
$('.grandtotal').val(result.toFixed(2));
if ($('.tf').is(':checked')) {
var resulttf = parVal - 25 * parVal / 100;
$('.tfboxval').val(resulttf.toFixed(2));
var result = result - resulttf;
$('.grandtotal').val(result.toFixed(2));
}
if ($('.sf').is(':checked')) {
//alert('entered');
var resultsf = parVal - 75 * parVal / 100;
$('.sfboxval').val(resultsf.toFixed(2));
var result = result - resultsf;
$('.grandtotal').val(result.toFixed(2));
}
}
$('.tf').click(function() {
$(".tfbox").toggle(this.checked);
});
$('.sf').click(function() {
$(".sfbox").toggle(this.checked);
});
in php i had
print_r($_POST['parti']);
its give out put
Array
(
[1] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
)
but i need
Array
(
[1] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
[2] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
[3] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
....
)
javascript
Please indent your code next time. Too many changes to make in your form. At the line where you have "Enter invoice no." you have left an open quote at value=""" which is a big mistake.
Overwrite your HTML code with this:
<div class="matter">
<div class="container">
<form method="POST" action="http://fabtech.com/invoices/create" accept-charset="UTF-8" role="form" class="form-horizontal re-form form-inv">
<input name="_token" type="hidden" value="aLngVzB1UIlY6cEedbAh55tirXGGkYJl78BL0CRN">
<div class="row">
<div class="col-md-12">
<legend>Invoice Details</legend>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Invoice No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter invoice no" class="form-control" name="inv_no" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Invoice date</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control date-pic" name="inv_date" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Customer</label>
<div class="col-md-7">
<select class="form-control" name="inv_customer">
<option value="">- Select Customer -</option>
<option value="suresh">suresh</option>
<option value="ABC210">ABC210</option>
<option value="QWERTy123DF">QWERTy123DF</option>
<option value="CUS002">CUS002</option>
<option value="CUS0023">CUS0023</option>
<option value="CUS003">CUS003</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control" name="po_no" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO date</label>
<div class="col-md-7">
<input type="text" placeholder="DD/MM/YYY" class="form-control date-pic" name="po_date" value="">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Vendor code</label>
<div class="col-md-7">
<input type="text" placeholder="Enter Vendor Code" class="form-control" name="vendor_code" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">75% abatement value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control sf" name="sf">
</div>
<div class="col-md-6 sfbox" style="display:none">
<input type="text" class="form-control sfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">25% Taxable Value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control tf" name="tf">
</div>
<div class="col-md-6 tfbox" style="display:none">
<input type="text" class="form-control tfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Tax in %</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control tax" name="tax" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Grand Total</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control grandtotal" readonly="" name="grand_total">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<legend>Particulars <a class="btn btn-xs btn-success" id="apm"><i class="icon-plus"></i> Add new</a>
</legend>
<table id="apmr" width="69%" class="table table-striped table-bordered table-hover invoice">
<thead>
<tr>
<th width="3%">
SL No
</th>
<th width="25%">
Description
</th>
<th width="8%">
Unit
</th>
<th width="8%">
Qty
</th>
<th width="10%">
Unit rate
</th>
<th width="9%">
Amount
</th>
</tr>
</thead>
<tbody class="roo">
<tr>
<td valign="center">
1
</td>
<td class="tr_nt">
<input type="text" name="parti[1][desc]" class="part">
</td>
<td class="tr_nt">
<input type="text" name="parti[1][unit]" class="part">
</td>
<td class="tr_qty into">
<input type="text" name="parti[1][qty]" class="part qty">
</td>
<td class="tr_urate into">
<input type="text" name="parti[1][urate]" class="part ur">
</td>
<td class="tr_amt">
<input type="text" name="parti[1][amount]" readonly="" class="part tot">
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
</td>
<td colspan="2">
Particular's Total: Rs <span class="parttotal"></span>
</td>
</tr>
</tfoot>
</table>
<p style="text-align: center;padding-top: 5px;">
<input name="submit" class="btn-lg btn-primary" type="submit" value="View Invoice">
</p>
</div>
</div>
</form>
</div>
</div>
Your mistake was that your <form> tag was closed in the wrong place. Remember to always place tags in such a way that always the inner tags close first.
Related
so im kinda new in codeigniter and web developing in general but is it possible to count Sub Total and Tax, automatically input that value into somekind of input box in codeigniter?
for example :
i have model that join some column and show the data into a table
table model.php
public function getPurchaseOrder()
{
$query =$this->db->query('SELECT dkmno, kodeprod,kodebarang_op,qty_op,unit_op,price,catatan FROM order_product JOIN barang_dkm ON order_product.kodebarang_op = barang_dkm.kodebarang');
return $query->result_array();
}
table view.php
<table class="table table-fixed table-bordered table-hover" style="width:100%;" id="tebal">
<thead>
<tr>
<th scope="col">DKM No </th>
<th scope="col">Kode Produksi </th>
<th scope="col">Kode Barang </th>
<th scope="col">Deskripsi </th>
<th scope="col">Jumlah/Quantity </th>
<th scope="col">Unit </th>
<th scope="col">Unit Price </th>
<th scope="col">Sub Total </th>
</tr>
</thead>
<tbody>
<?php foreach ($dataTabel as $kiki) : ?>
<tr class="table-row">
<td><?php echo $kiki["dkmno"]; ?></td>
<td><?php echo $kiki["kodeprod"]; ?></td>
<td><?php echo $kiki["kodebarang_op"]; ?></td>
<td><?php echo $kiki["catatan"]; ?></td>
<td><?php echo $kiki["qty_op"]; ?></td>
<td><?php echo $kiki["unit_op"]; ?></td>
<td><?php echo $kiki["price"]; ?></td>
<td class="calc"><?php $a=$kiki["qty_op"]*$kiki["price"]; echo $a ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
and i want to count sub total from the table above and show the answer in a textbox or inputbox
subtotal, discount, and tax code if you want to know
<div class="row mt-5">
<div class="col-sm" id="kontol">
<div class="form-group">
<div class="row">
<div class="col-sm-3">
<label for="SubTotal" class="control-label">Sub Total : </label>
</div>
<div class="col-sm-9">
<input type="number" id="subTotal" name="SubTotal" value="" style="text-align: right;" class="form-control" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-3">
<label for="Discount" class="label-control" id="Discount">Discount : </label>
</div>
<div class="col-lg-3">
<div class="input-group">
<input type="number" name="Discount" class="form-control" id="inputDiscount" value="" min="0" max="100" onchange="calculatedSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-lg-6">
<input type="number" name="SubTotalDiscount" value="" style="text-align: right;" class="form-control" id="subTotalDiscount" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-3">
<label for="Tax" class="label-control">Tax : </label>
</div>
<div class="col-lg-3">
<div class="input-group">
<input type="number" name="Tax" value="" min="0" max="100" class="form-control" id="inputTax" onchange="calculatedSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-lg-6">
<input type="number" name="SubTotalTax" style="text-align: right;" class="form-control" id="subTotalTax" value="" disabled>
</div>
</div>
</div>
i have try to look at people who ask the same question but i still need somekind a detail how the model.php, controller.php, view.php, script.js work, if you need more details here's the link the ui that i already made : https://i.imgur.com/LSkrnMH.png
You could get the subtotal using CodeIgniter, but you have to use javascript to calculate the tax because it involves user interaction.
For example you have the subtotal input like this :
<div class="form-group">
<label class="col-sm-3 control-label" for="SubTotal">Sub Total</label>
<div class="col-sm-9">
<input type="number" name="SubTotal" id="subTotal" class="form-control" value="" title="Sub Total" disabled><br/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="Discount">Discount</label>
<div class="col-sm-9">
<div class="col-sm-6">
<div class="input-group input-group-md">
<input type="number" name="Discount" id="inputDiscount" class="form-control" value="" title="Discount" min="0" max="100" onchange="calculateSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-sm-6">
<input type="number" name="SubTotalDiscount" id="subTotalDiscount" class="form-control" value="" title="Subtotal After Discount" disabled><br/>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="Tax">Tax</label>
<div class="col-sm-9">
<div class="col-sm-6">
<div class="input-group input-group-md">
<input type="number" name="Tax" id="inputTax" class="form-control" value="" title="Tax" min="0" max="100" onchange="calculateSubTotal()"><span class="input-group-addon">%</span>
</div>
</div>
<div class="col-sm-6">
<input type="number" name="SubTotalTax" id="subTotalTax" class="form-control" value="" title="Subtotal After Tax" disabled><br/>
</div>
</div>
</div>
Then you could set the subtotal value and also count the subtotals value after discount and after tax like this :
<script>
jQuery(function () {
let sum = 0.0;
jQuery('.calc').each(function() {
sum += parseInt(jQuery(this).text());
});
jQuery("#subTotal").val(sum);
});
function calculateSubTotal() {
let subtotal = jQuery("#subTotal").val();
jQuery("#subTotalDiscount").val(subtotal - (Math.round((jQuery("#inputDiscount").val() / 100) * subtotal)));
let subtotal_discount = jQuery("#subTotalDiscount").val();
jQuery("#subTotalTax").val(+subtotal_discount + (Math.round((jQuery("#inputTax").val() / 100) * subtotal_discount)));
}
</script>
That will set all of the subtotals using javascript instead.
Try this:
$this->db->select_sum('your_column_to_calculate');
$this->db->select('your_column_to_calculate');
$this->db->from('price');
$this->db->get();
or like this:
query = $this->db->query('SELECT sum(your_column_to_calculate) FROM price');
Hope it helps
This is javascript code,This calculate the only the calc row and show the result in subtotal text box and it will load automatically:
<script>
$(document).ready(function(){
var hh2 = 0;
$('#tebal > tbody > tr').each(function() {
var price = $(this).find('.calc').val();
hh2 += parseFloat(price);
});
$('#SubTotal').val(hh2);
});
</script>
you can count all of the sum with php itself
set variable $subtotal with zero, and add $subtotal in every loop
<?php
$subtotal = 0;
foreach ($dataTabel as $kiki) : ?>
<tr class="table-row">
....
</tr> <?php $subtotal = $subtotal+$kiki["qty_op"]*$kiki["price"]; endforeach;?>
Hope you get it.
i have problem at the time of input data to the database
this is error message
A Database Error Occurred
Error Number: 1048
Column 'username_member' cannot be null
INSERT INTO member (id_member, username_member,
password_member, nama_member, jk_member, hp_member,
alamat_member, email_member) VALUES (NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL)
Filename: C:/AppServ/www/PROJEK/system/database/DB_driver.php
Line Number: 691
my controller
function tambah()
{
$data = array(
'aksi' => site_url('member/tambah_aksi'),
'id_member' => set_value('id_member'),
'username_member' => set_value('username_member'),
'password_member' => set_value('password_member'),
'nama_member' => set_value('nama_member'),
'jk_member' => set_value('jk_member'),
'hp_member' => set_value('hp_member'),
'alamat_member' => set_value('alamat_member'),
'email_member' => set_value('email_member'),
'button' => 'DAFTAR'
);
$this->load->view('Utama/member_form', $data);
}
function tambah_aksi()
{
$data = array(
'id_member' => $this->input->post('id_member'),
'username_member' => $this->input->post('username_member'),
'password_member' => $this->input->post('password_member'),
'nama_member' => $this->input->post('nama_member'),
'jk_member' => $this->input->post('jk_member'),
'hp_member' => $this->input->post('hp_member'),
'alamat_member' => $this->input->post('alamat_member'),
'email_member' => $this->input->post('email_member')
);
$this->member_model->tambah_data($data);
redirect('Login_member');
}
View
<h3> FORM <i class="icon-arrow-left"></i> LANJUT BERBELANJA </h3> <hr class="soft"/> <table class="table table-bordered">
<tr><th> FORM DAFTAR MEMBER </th></tr>
<form action="<?php echo $aksi; ?>" method="get" class="form-horizontal" enctype="multipart/form-data">
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputUsername">Username</label>
<div class="controls">
</td>
<td>
<input type="text" name="username_member" class="form-control" placeholder="Inputkan Username" value="">
</div>
</div>
</td>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Password</label>
<div class="controls">
</td>
<td>
<input type="password" name="password_member" placeholder="Password" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Nama Member</label>
<div class="controls">
</td>
<td>
<input type="text" name="nama_member" placeholder="ex : Eden Hazard" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Jenis Kelamin</label>
<div class="controls">
</td>
<td>
<input type="radio" name="jk_member" value="Laki">Pria
<br>
<input type="radio" name="jk_member" value="Wanita">Wanita
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">No Hp</label>
<div class="controls">
</td>
<td>
<input type="text" name="hp_member" placeholder="ex : 08127516331" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Alamat Lengkap</label>
<div class="controls">
</td>
<td>
<input type="text" name="alamat_member" placeholder="ex : perum pandau blok c.19 no.16, Pekanbaru, Riau" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Email</label>
<div class="controls">
</td>
<td>
<input type="text" name="email_member" placeholder="ex : randy#yahoo.com" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="id_member" value="<?php echo $id_member; ?>">
<button class="btn btn-primary" type="submit"><?php echo $button; ?></button>
</td>
</tr>
</form>
You want to change your forms method from get to post as you are processing POST data.
So your line
<form action="<?php echo $aksi; ?>" method="get" class="form-horizontal" enctype="multipart/form-data">
Change the get to post for your method.
<form action="<?php echo $aksi; ?>" method="post" class="form-horizontal" enctype="multipart/form-data">
See how that flies.
My view is like i want to show the selected textbox price and code to the controller
how can i do this
<div>
<!--second line start-->
<?php
foreach ($enq_info as $ei) {
echo form_open_multipart("Quotation/prepareQuote2/$ei->eid");
if (!empty($quote_data)) {
?>
<input name="quote_check" value="1" type="text" class="form-control">
<?php
} else {
?>
<input name="quote_check" value="no" type="text" class="form-control">
<?php
}
?>
<div class="form-group">
<div class="col-sm-2">
<label for="firstname">Enquiry Id</label>
<input name="e_id" id="e_id" value="<?php echo $ei->eid;?>" type="text" class="form-control">
</div>
<div class="col-sm-3">
<label for="lastname">Company Name</label>
<input type="text" name="company_name" id="company_name" value="<?php echo $ei->company_name;?>" class="form-control" />
</div>
<div class="col-sm-3">
<label for="lastname">Contact Person</label>
<input type="text" name="c_person" id="c_person" value="<?php echo $ei->c_person;?>" class="form-control"/>
</div>
<div class="col-sm-4">
<label>Address</label>
<textarea class="form-control" id="address" name="address" value="<?php echo $ei->address;?>"><?php echo $ei->address;?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<label for="firstname">Attn Department</label>
<textarea class="form-control" id="dept" name="dept" value="">
<?php
echo $ei->c_person." Tel ";
if(empty($ei->p_contact))
echo $ei->c_contact;
else
echo $ei->p_contact;
?>
</textarea>
</div>
<div class="col-sm-3">
<label for="lastname">Quotation For</label>
<select id="quotation_type" name="quotation_type" class="form-control m-b">
<option value="Q_Manager">Q-Manager Quote</option>
<option value="Q_Master">Q-Master Quote</option>
<option value="Q_Manager_repair">Q-Manager Repair Quote</option>
</select>
</div>
<div class="col-sm-3">
<label for="lastname">Discount</label>
<textarea class="form-control" id="discount" name="discount"></textarea>
</div>
<div class="col-sm-3">
<label for="lastname"></label><br><br>
<input type="submit" class="btn btn-success" id="default_quote" value="Generate Default Quote" onClick="rerurn disable1();"/>
</div>
</div>
<div id="showquote">
<div class="row">
<div class="hpanel">
<div class="panel-body">
<div class="col-md-12">
<table class="table table-bordered table-striped">
<tr>
<td>Product Name</td>
<td>Product Code</td>
<td>Price</td>
<td>Action</td>
</tr>
<?php
// print_r($quote_data);
foreach ($product_data as $qd) {
?>
<tr>
<td><?php echo $qd->cp_name;?></td>
<td><?php echo $qd->cp_code;?></td>
<td>
<input type="text" name="product_price[]" value="<?php echo $qd->p_price;?>">
</td>
<td>
<input type="checkbox" name="product_name[]" value="<?php echo $qd->cp_name;?>" checked/>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
<?php echo form_close(); ?>
<br><br>
<!--for new manual quote-->
<?php
}
?>
<!--third line start-->
how can i send the selected values price and also product code to the controller
just add the product code - product price with comma seperated in a hidden field like below
12-20000,13-30000,14-200 and so on
and once received in controller process it with explode or other way.
hopes you understood.
I have a roles called read,write,and delete operation for a list of menu.I am listing menu with read,write,delete operation with a checkbox to insert to database but when i try to insert its not inserting multiple its inserting has one row in mysql here my code
database
Code
Form.php
<form method="post" action="insertuser.php" class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="username" id="username" required>
<span class="help-block">Please Enter Username</span>
<span class="help-block" id="name_status"></span>
</div>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="password" id="password" required>
<span class="help-block">Please Enter Password</span>
</div>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="emailaddress" id="emailaddress" required>
<span class="help-block">Please Enter Email Address</span>
<span class="help-block" id="name_status1"></span>
</div>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Role Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="rolename" id="rolename" required>
<span class="help-block">Please Enter Role Name</span>
<span class="help-block" id="name_status2"></span>
</div>
</div>
</fieldset>
<table id="example" class="table table-striped table-bordered" >
<thead>
<th data-field="id" data-sortable="true">Menu Name</th>
<th data-field="name" data-sortable="true">Read</th>
<th data-field="actions" data-sortable="true">Edit</th>
<th data-field="actions" data-sortable="true">Delete</th>
</thead>
<tbody>
<?php
$i=0;
$selectquery=mysql_query("select * from menumanagement");
while($row=mysql_fetch_array($selectquery))
{
?>
<tr>
<td><?php echo $row["mn_menuname"]; ?></td>
<td>
<label class="checkbox checkbox-inline checked">
<span class="icons"><span class="first-icon fa fa-square-o"></span><span class="second-icon fa fa-check-square-o"></span></span><input type="checkbox" name="read1[]" id="read1" value="1_<?php echo $row["mn_id"]; ?>">
</label>
</td>
<td>
<label class="checkbox checkbox-inline checked">
<span class="icons"><span class="first-icon fa fa-square-o"></span><span class="second-icon fa fa-check-square-o"></span></span><input type="checkbox" name="edit1[]" id="edit1" value="1_<?php echo $i."_".$row["mn_id"]; ?>">
</label>
</td>
<td>
<label class="checkbox checkbox-inline checked">
<span class="icons"><span class="first-icon fa fa-square-o"></span><span class="second-icon fa fa-check-square-o"></span></span><input type="checkbox" name="delete1[]" id="delete1" value="1_<?php echo $i."_".$row["mn_id"]; ?>">
</label>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<center><button type="submit" class="btn btn-fill btn-warning btn-wd" id="addmenu">Add User</button></center>
</div>
</form>
Insert.php
<?php
include_once("includes/db.php");
if(!empty($_POST["username"]))
{
$username=$_POST["username"];
}
if(!empty($_POST["password"]))
{
$password=$_POST["password"];
}
if(!empty($_POST["emailaddress"]))
{
$emailaddress=$_POST["emailaddress"];
}
$insertquery=mysql_query("insert into useraccess(useraccess_username,useraccess_password,useraccess_emailaddress) values ('$username','$password','$emailaddress')");
$userid=mysql_insert_id();
if($insertquery)
{
if(empty($_POST["read1"]))
{
$readid=0;
}
if(empty($_POST["edit1"]))
{
$editid=0;
}
if(empty($_POST["delete1"]))
{
$deleteid=0;
}
if($_POST["read1"])
{
$readid="";
$menuid="";
$countread=count($_POST["read1"]);
for($i=0;$i<$countread;$i++)
{
$read1=$_POST["read1"][$i];
$readdiv =explode("_", $read1);
$readid .=$readdiv[0];
$menuid .=$readdiv[1];
}
}
if($_POST["edit1"])
{
$editid="";
$menuid="";
$countedit=count($_POST["edit1"]);
for($i=0;$i<$countedit;$i++)
{
$edit1=$_POST["edit1"][$i];
$editdiv=explode("_", $edit1);
$editid .=$editdiv[0];
$menuid .=$editdiv[1];
}
}
if($_POST["delete1"])
{
$deleteid="";
$menuid="";
$countdelete=count($_POST["delete1"]);
for($i=0;$i<$countdelete;$i++)
{
$delete1=$_POST["delete1"][$i];
$deletediv=explode("_", $delete1);
$deleteid .=$deletediv[0];
$menuid .=$deletediv[1];
}
}
$insertquery1=mysql_query("insert into rolemanagement(menuid,role_read,role_write,role_delete,userid) value ('$menuid','$readid','$editid','$deleteid','$userid')");
if($insertquery1)
{
header('Location: adduser.php?status="Role has been added"');
}
}
?>
Regards
I created a search page with jquery that will display result on same page and I succeed of doing it but the jquery that I made can only show data with index 0 and it will fail if I searched other data with differenct index. I am having Uncaught TypeError: Cannot read property 'StudentNumber' of undefined error in console log.How can I search json object with data matching what is type in the search bar then populate the textbox from db. Please help.... thanks....
$('#btnSearch').click(function(){
var txtValue = $("#txtsearch").val();
$.ajax({
type:"POST",
url:"<?php echo site_url('enrollment/studSearch');?>",
data: {q:txtValue},
dataType: "json",
success: function(data){
//console.log(data.studinfo[0].StudentNumber);
$("#studentnum").val(data.studinfo[0].StudentNumber);
$("#yearLevel").val(data.studinfo[0].YearLevel);
$("#lastname").val(data.studinfo[0].LastName);
$("#firstname").val(data.studinfo[0].FirstName);
$("#middlename").val(data.studinfo[0].MiddleName);
$("#txtTuition").val(data.studinfo[0].TuitionFee);
$("#txtMisc").val(data.studinfo[0].MiscFee);
$("#txtAddFee").val(data.studinfo[0].AdditionalFee);
$("#txtTotal").val(data.studinfo[0].Total);
$("#modeofpayment").val(data.studinfo[0].ModeOfPayment);
$("#payAmount").val(data.studinfo[0].PayableAmount);
},
});
});
my controller:
public function studSearch()
{
$str = $this->input->post('q');
$data['studinfo'] = $this->emodel->search_Student($str);
echo json_encode($data);
}
and the model:
function search_Student($str)
{
$this->db->select('*');
$this->db->from('studentinfo a');
$this->db->join('studFinance b','a.StudentNumber = b.StudentNumber');
$this->db->like('a.StudentNumber',$str);
$this->db->or_like('a.LastName',$str);
$this->db->or_like('a.FirstName',$str);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
this is the view:
<div id="page-wrapper">
<div id="page-inner">
<div class="row">
<div class="col-lg-12">
<h2>Billing Page</h2>
</div>
</div>
<hr />
<div class="row">
<div class="col-lg-12">
<?php
$attributes = array("class"=>"form- horizontal","id"=>"billform","name"=>"billform",
"autocomplete"=>"off");
echo form_open("enrollment/ebilling",$attributes);
?>
<div class="panel panel-primary">
<div class="panel-heading">
Personal Information
</div>
<div class="panel-body">
<div class="form-group col-lg-12">
<label class="control-label col-xs-2">Search:</label>
<div class="col-xs-3">
<input type="text" id="txtsearch" name="txtsearch" class="form-control"/>
</div>
<button type="button" class="btn btn-success" id="btnSearch" name="btnSearch">Search</button>
</div>
<div class="form-group col-lg-12">
<hr />
<label class="control-label col-xs-2">Student Number:</label>
<div class="col-xs-3">
<input type="text" readonly id="studentnum" name="studentnum" value="<?php echo set_value('studentnum');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-2">Year Level:</label>
<div class="col-xs-3">
<input type="text" readonly id="yearLevel" name="yearLevel" value="<?php echo set_value('yearLevel');?>" class="form-control"/>
</div>
<label class="control-label col-xs-2">Last Name:</label>
<div class="col-xs-3">
<input type="text" id="lastname" name="lastname" value="<?php echo set_value('lastname');?>" readonly class="form-control" />
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-2">First Name:</label>
<div class="col-xs-3">
<input type="text" id="firstname" name="firstname" value="<?php echo set_value('firstname');?>" readonly class="form-control" />
</div>
<label class="control-label col-xs-2">Middle Name:</label>
<div class="col-xs-3">
<input type=-"text" id="middlename" name="middlename" value="<?php echo set_value('middlename');?>" readonly class="form-control" />
</div>
</div>
</div>
</div>
<!-- END OF FIRST PANEL -->
<div class="panel panel-primary">
<div class="panel-heading">
Billing Mode
</div>
<div class="panel-body">
<div class="col-lg-6">
<div class="panel panel-info">
<div class="panel-heading">
Student Account
</div>
<div class="panel-body">
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Tuition Fee:</label>
<div class="col-xs-7">
<input type="text" id="txtTuition" readonly name="txtTuition" value=" <?php echo set_value('txtTuition');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Miscellaneous Fee:</label>
<div class="col-xs-7">
<input type="text" id="txtMisc" readonly name="txtMisc" value="<?php echo set_value('txtMisc');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Additional Fee:</label>
<div class="col-xs-7">
<input type="text" id="txtAddFee" readonly name="txtAddFee" value="<?php echo set_value('txtAddFee');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Total:</label>
<div class="col-xs-7">
<input type="text" id="txtTotal" readonly name="txtTotal" value="<?php echo set_value('txtTotal');?>" class="form-control"/>
</div>
</div>
</div>
</div>
<!-- END OF FIRST INSIDE PANEL -->
<div class="panel panel-info">
<div class="panel-heading">
Payment
</div>
<div class="panel-body">
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Mode of Payment:</label>
<div class="col-xs-7">
<input type="text" id="modeofpayment" name="modeofpayment" value="<?php echo set_value('modeofpayment');?>" readonly class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Payable Amount:</label>
<div class="col-xs-7">
<input type="text" id="payAmount" name="payAmount" value="<?php echo set_value('payAmount');?>" readonly class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Date:</label>
<div class="col-xs-7">
<input type="date" id="pDate" name="pDate" value="<?php echo set_value('pDate');?>" class="form-control"/>
<span class="text-danger"><?php echo form_error('pDate');?></span>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">OR Number:</label>
<div class="col-xs-7">
<input type="text" id="orNum" name="orNum" value="<?php echo set_value('orNum');?>" class="form-control"/>
<span class="text-danger"><?php echo form_error('orNum');?></span>
<input type="hidden" id="balance" name="balance"/>
</div>
</div>
<!-- END OF SECOND INSIDE PANEL -->
</div>
</div>
</div>
<div class="col-lg-6">
<table id="billTable" class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th>OR Number</th>
<th>Amount</th>
<th>Date</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<td>Balance</td>
</tfoot>
</table>
</div>
<!-- END OF TABLE -->
<div class="col-lg-6">
<div class="form-group col-lg-12">
<input type="button" class="btn btn-success" id="btnAddPayment" name="btnAddPayment"
value="Add Payment"/>
<button type="reset" class="btn btn-danger" id="btnReset" name="reset">Reset</button>
</div>
</div>
</div>
</div>
<?php echo form_close();
echo $this->session->flashdata('msg');?>
</div>
</div>
</div>
</div>