Dynamic input not recorded in array PHP - php

I am making a simple add of items to inventory software which gets the data and adds to database using dynamic inputs.
<div class="col-lg-6">
<form action="invoice_check.php" method="POST">
<div class="row">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover table-medicines">
<thead>
<tr>
<th>Name</th>
<th>MFR</th>
<th>Quantity</th>
<th>Batch</th>
<th>Expiry</th>
<th>MRP</th>
<th>DSC</th>
<th> </th>
</tr>
</thead>
<tbody>
<tr>
<td style="width:20%;"><div class="form-group"><input id="1" class="form-
control" placeholder="Name" type="text" name="mname[]"></input></div></td>
<td><div class="form-group"><input class="form-control"
placeholder="Manufacturer" name="mfg[]"></div></td>
<td style="width:10%;"><div class="form-group"><input class="form-control"
placeholder="Qty" name="qty[]"></div></td>
<td style="width:10%;"><div class="form-group"><input class="form-control"
placeholder="Batch" name="batch[]"></div></td>
<td><div class="form-group"><input class="form-control" placeholder="MM/YY"
id="cc" name="exp[]"></div></td>
<td style="width:10%;"><div class="form-group"><input class="form-control"
placeholder="MRP" name="mrp[]"></div></td>
<td style="width:10%;"><div class="form-group"><input class="form-control"
placeholder="DSC" name="dsc[]"></div></td>
<td>
-
</td>
</tr>
</tbody>
</table>
</div>
</div>
<input type="submit" class="btn btn-primary btn-lg btn-block">
</form>
I have the following jquery for adding the a new Which contains the new input set.
The problem is that although the row gets added, when submitted the array doesn't contain the data of the appended input items.
For example, how many ever inputs i add, that data is never recorded even though I have used the array for the inputs.
I know the scripting of array isn't an issue since I have tried by using the same code as another without adding by jquery and the array has recorded the data.
<script>
$(document).ready(function() {
var wrapper = $(".table-medicines"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x=1;
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
x++;
$(wrapper).append('<tr> <td><div class="form-group"><input class="form-control" id="'+x+'" placeholder="Name" type="text" name="mname[]"/></div></td> <td><div class="form-group"><input class="form-control" placeholder="Manufacturer" name="mfg[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="Qty" name="qty[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="Batch" name="batch[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="Expiry" name="exp[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="MRP" name="mrp[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="DSC" name="dsc[]"></div></td> <td> <button type="button" class="add_field_button btn btn-danger btn-circle"><i class="fa fa-times "></i></button> </td> </tr>'); //add input box
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).closest('tr').remove(); x--;
})
});
Thanks in advance.

At first, when the DOM is loading, you won't get the Add new button as it is generating inside its self click event. So you have to initialize it on loading. Rest of the things are correct except few minor changes.
$(document).ready(function() {
var wrapper = $(".table-medicines"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x=1;
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
x++;
$(wrapper).append('<tr> <td><div class="form-group"><input class="form-control" id="'+x+'" placeholder="Name" type="text" name="mname[]"/></div></td> <td><div class="form-group"><input class="form-control" placeholder="Manufacturer" name="mfg[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="Qty" name="qty[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="Batch" name="batch[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="Expiry" name="exp[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="MRP" name="mrp[]"></div></td> <td><div class="form-group"><input class="form-control" placeholder="DSC" name="dsc[]"></div></td> <td> <button type="button" class="remove_field btn btn-danger btn-circle"><i class="fa fa-times "></i>Remove</button></td> </tr>'); //add input box
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).closest('tr').remove(); x--;
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="col-lg-6">
<form action="invoice_check.php" method="POST">
<div class="row">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover table-medicines">
<thead>
<tr>
<th>Name</th>
<th>MFR</th>
<th>Quantity</th>
<th>Batch</th>
<th>Expiry</th>
<th>MRP</th>
<th>DSC</th>
<th> </th>
</tr>
</thead>
<tbody>
<tr>
<td style="width:20%;">
<div class="form-group"><input id="1" class="form-
control" placeholder="Name" type="text" name="mname[]"></input></div>
</td>
<td>
<div class="form-group"><input class="form-control"
placeholder="Manufacturer" name="mfg[]"></div>
</td>
<td style="width:10%;">
<div class="form-group"><input class="form-control"
placeholder="Qty" name="qty[]"></div>
</td>
<td style="width:10%;">
<div class="form-group"><input class="form-control"
placeholder="Batch" name="batch[]"></div>
</td>
<td>
<div class="form-group"><input class="form-control" placeholder="MM/YY"
id="cc" name="exp[]"></div>
</td>
<td style="width:10%;">
<div class="form-group"><input class="form-control"
placeholder="MRP" name="mrp[]"></div>
</td>
<td style="width:10%;">
<div class="form-group"><input class="form-control"
placeholder="DSC" name="dsc[]"></div>
</td>
<td><button type="button" class="add_field_button btn btn-danger btn-circle"><i class="fa fa-times "></i>Add</button> </td>
</tr>
</tbody>
</table>
</div>
</div>
<input type="submit" class="btn btn-primary btn-lg btn-block">
</form>

Related

How to align bootstrap columns in print page #media print?

Bootstrap columns not taking in print page and aligned wrongly how to rectify this issue?
I dont need responsive page but need to align the print page. Can anyone plz help me out?
#media print {
#page {
margin: 2cm;
}
.col-md-1,.col-md-2,.col-md-3,.col-md-4,
.col-md-5,.col-md-6,.col-md-7,.col-md-8,
.col-md-9,.col-md-10,.col-md-11,.col-md-12 {
float: left;
}
.col-md-1 {
width: 8%;
}
.col-md-2 {
width: 16%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33%;
}
.col-md-5 {
width: 42%;
}
.col-md-6 {
width: 50%;
float: left;
}
.col-md-7 {
width: 58%;
}
.col-md-8 {
width: 66%;
}
.col-md-9 {
width: 75%;
}
.col-md-10 {
width: 83%;
}
.col-md-11 {
width: 92%;
}
.col-md-12 {
width: 100%;
}
}
HTML PAGE
[<div class="container border border-dark" id="container">
<div class="row">
<div style="font-size:25px; font-weight:bold; text-decoration: underline;" class="col-md-10">KERCHANSHE TRADING PLC
<div style="font-size:15px;margin-right: 5px;margin-left: 34px;"><i class="fa fa-mobile" style="font-size:18px;margin-right: 5px;" aria-hidden="true"></i> 091 121 2436
<i class="fa fa-phone" style="font-size:18px;margin-right: 5px;margin-left: 31px;" aria-hidden="true"></i> 011 371 6370</div>
<div style="font-size:15px;margin-left: 80px;">Addis Ababa, Ethiopia</div>
</div>
<div style="font-size:20px; font-weight:bold; border: 1px solid black;text-align: center;height: min-content;"
class="col-md-2 border border-dark">ORIGNAL</div>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="MinVal">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="MaxVal">
</div>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-4" style="margin-left: 18px;">
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Cert. No</span>
</div>
<input type="text" id="cert1_no" class="form-control input-sm" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-4" style="margin-left: 18px;">
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-sm">Addis Ababa</span>
</div>
<input type="text" id="addis_ababa" class="form-control input-sm" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
</div>
</div>
</div>
<div class="row">
<div class="col-xl-5 col-lg-6 col-md-8 col-sm-10 mx-auto text-center form p-4">
<span style="font-size:30px; font-weight:bold; text-decoration: underline;">CERTIFICATE</span>
</div>
</div>
<span style="font-size:20px; text-decoration: underline;margin-left: 19%;">
<b>CERTIFICATE OF CLEANLINESS AND GRADE OF ETHIOPIAN COFFEE</b>
</span><br/><br/>
<div class="row">
<div class="col-md-3">
<input name="origin" type="text" class="form-control" id="origin_cert1"/>
<span style="">(Origin)</span>
</div>
<div class="col-md-9">
<span class="pull-right"> <input name="grade" type="text" class="form-control" id="grade_cert1"/>
<span style="">(Grade)</span>
</span>
</div>
</div>
<br>
<div style="font-size:15px;">
<p style="text-align: center;font-weight: 700; font-size: 18px;">Description of Lot</p>
<table class="table tablecert1 table-bordered">
<tr>
<th colspan="4" style="text-align: center;">BAGS</th>
</tr>
<tr>
<th rowspan="2" style="text-align: center;">No</th>
<th colspan="2" style="text-align: center;">Weight</th>
<th rowspan="2" style="text-align: center;">Mark</th>
</tr>
<tr>
<th style="text-align: center;">Gross</th>
<th style="text-align: center;">Net</th>
</tr>
<tr>
<td><input style="" id="no_1" class="form-control no" type="text"></td>
<td><input style="" id="gross_1" class="form-control gross" type="text"></td>
<td><input style="" id="net_1" class="form-control net" type="text"></td>
<td><input style="" id="mark_1" class="form-control mark" type="text"></td>
</tr>
<tr>
<td><input style="" id="no_2" class="form-control no" type="text"></td>
<td><input style="" id="gross_2" class="form-control gross" type="text"></td>
<td><input style="" id="net_2" class="form-control net" type="text"></td>
<td><input style="" id="mark_2" class="form-control mark" type="text"></td>
</tr>
<tr>
<td><input style="" id="no_3" class="form-control no" type="text"></td>
<td><input style="" id="gross_3" class="form-control gross" type="text"></td>
<td><input style="" id="net_3" class="form-control net" type="text"></td>
<td><input style="" id="mark_3" class="form-control mark" type="text"></td>
</tr>
<tr>
<td><input style="" id="no_4" class="form-control no" type="text"></td>
<td><input style="" id="gross_4" class="form-control gross" type="text"></td>
<td><input style="" id="net_4" class="form-control net" type="text"></td>
<td><input style="" id="mark_4"class="form-control mark" type="text"></td>
</tr>
<tr>
<td><input style="" id="no_5" class="form-control no" type="text"></td>
<td><input style="" id="gross_5" class="form-control gross" type="text"></td>
<td><input style="" id="net_5" class="form-control net" type="text"></td>
<td><input style="" id="mark_5" class="form-control mark" type="text"></td>
</tr>
<tr>
<td><input style="" id="no_6" class="form-control no" type="text"></td>
<td><input style="" id="gross_6" class="form-control gross" type="text"></td>
<td><input style="" id="net_6" class="form-control net" type="text"></td>
<td><input style="" id="mark_6" class="form-control mark" type="text"></td>
</tr>
</table>
</table>
</div>
<div class="row">
<div class="input-group mb-1 col-md-6">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Driver's Name</span>
</div>
<input type="text" class="form-control" id="driversname" aria-label="Username" aria-describedby="basic-addon1">
</div>
</div>
<div class="row">
<div class="input-group mb-1 col-md-6">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Truck Plate No.</span>
</div>
<input type="text" class="form-control" id="truckplateno" aria-label="Username" aria-describedby="basic-addon1">
</div>
</div>
<div class="row">
<div class="input-group mb-1 col-md-6">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Trailer No.</span>
</div>
<input type="text" class="form-control" id="trailerno" aria-label="Username" aria-describedby="basic-addon1">
</div>
</div>
<div class="row">
<div class="input-group mb-1 col-md-6">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Container No.</span>
</div>
<input type="text" class="form-control" id="containerno" aria-label="Username" aria-describedby="basic-addon1">
</div>
<div class="form-inline">
<label for="exampleInputEmail1" style="MARGIN-LEFT: 50PX;font-weight: 700;text-decoration:overline;">KERCHANSHE TRADING PLC</label>
</div>
</div>
<div class="row">
<div class="input-group mb-1 col-md-6">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Seal No.</span>
</div>
<input type="text" class="form-control" id="sealno" aria-label="Username" aria-describedby="basic-addon1">
</div>
</div><br>
<div class="row">
<div class="form-group form-inline">
<label for="exampleInputEmail1" style="MARGIN-LEFT: 550PX;font-weight: 700;text-decoration:overline;">Signature of Licensed Coffee Cleaners & Graders</label>
</div>
</div>
</div>][1]
I have attached my print page please find it. And suggest me where i have to change the code in media print in css??
Actually the page should like this
real page should be like this
print wrong page looks like
print page
function printDiv_kerch() {
var divToPrint = document.getElementById('container');
var newWin = window.open('', 'Print-Window', '');
newWin.document.open();
newWin.document.write('<html><head>');
newWin.document.write('<link rel="stylesheet" type="text/css" media="print" href="http://localhost/verbat/css/certi.css"></head>');
newWin.document.write('<link rel="stylesheet" type="text/css" media="print" href="http://localhost/verbat/bootstrap-4.3.1-dist/bootstrap.min.css"></head>');
newWin.document.write('<body style="" onload="window.print();window.close();">' + divToPrint.innerHTML + '');
newWin.document.write('</body></html>');
newWin.document.close();
setTimeout(function() {
newWin.close();
}, 500);
}

how to Update data in a table using jquery ajax php and mysql

I would appreciate your help!
The situation is as follows:
There are two tables with data from the database.
The number of tables actually depends on the user who will post them. I used "while cycle method" to post the table with data on the page.
So, now I want the data in each of these tables could be changed by clicking the Update button.
Each table has it's own ID.
I found many solutions on Youtube with the usage of jquery ajax php and mysql.
I have tried this code below so far:
<html>
<!-- My table structure which cannot be chanhed -->
<?php
while ($row = mysqli_fetch_array($result_set)):;
?>
<table class="myTable" cellspacing="5">
<tbody>
<tr id="<?php echo $row['id'];?>">
<th>Title</th>
<td data-target="title" class="title"><b><?php echo
$row['title'];?></b></td>
</tr>
<tr>
<th>Description</th>
<td data-target="description"><p class="description"
align="justify"><?php echo $row['description'];?></p></td>
</tr>
<tr>
<th>Phone number</th>
<td data-target="tel"><?php echo $row['tel'];?></td>
</tr>
<tr>
<th>---</th>
<td><a href="#" data-role="update" data-id="<?php echo
$row['id'];?>">Update</a></td>
</tr>
</tbody>
</table>
<?php endwhile;?>
<!-- Bootstrap Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×
</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body" align="center">
<div class="form-group">
<label>Title</label>
<textarea id="title" name = "title" rows = "1" cols = "60"
required></textarea>
</div>
<div class="form-group">
<label>Description</label>
<textarea id="description" name = "description" rows = "20"
cols = "60" required></textarea>
</div>
<div class="form-group">
<label>Phone number (optional)</label>
<input type="text" id="tel" name="tel"/>
</div>
</div>
<div class="modal-footer">
<a href="#" id="save" class="btn btn-primary pull-
right">Update</a>
<button type="button" class="btn btn-default pull-left" data-
dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</html>
An here is I have a problem!!! Because the children method is not working for my TABLE structure! But I cannot find another solution.
<script>
$(document).ready(function(){
$(document).on('click','a[data-role=update]',function(){
var id = $(this).data('id');
var title = $('#'+id).children('td[data-target=title]').text();
var description = $('#'+id).children('td[data-
target=description]').text();
var tel = $('#'+id).children('td[data-target=tel]').text();
$('#title').val(title);
$('#description').val(description);
$('#tel').val(tel);
$('#myModal').modal('toggle');
})
});
</script>
Your problem is caused because the elements are not immediate children of #id. So you have to target a different element to start with. And then, since they are descendants (not children), use a different function that can find them.
$(document).ready(function() {
$(document).on('click', 'a[data-role=update]', function() {
var $body = $(this).closest('tbody');
var title = $body.find('td[data-target=title]').text().trim();
var description = $body.find('td[data-target=description]').text().trim();
var tel = $body.find('td[data-target=tel]').text().trim();
$('#title').val(title);
$('#description').val(description);
$('#tel').val(tel);
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<table class="myTable" cellspacing="5">
<tbody>
<tr id="1">
<th>Title</th>
<td data-target="title" class="title">
<b>Title</b></td>
</tr>
<tr>
<th>Description</th>
<td data-target="description">
<p class="description" align="justify">
Description
</p>
</td>
</tr>
<tr>
<th>Phone number</th>
<td data-target="tel">
Phone
</td>
</tr>
<tr>
<th>---</th>
<td>Update</td>
</tr>
</tbody>
</table>
<div class="form-group">
<label>Title</label>
<textarea id="title" name="title" rows="1" cols="60" required></textarea>
</div>
<div class="form-group">
<label>Description</label>
<textarea id="description" name="description" rows="20" cols="60" required></textarea>
</div>
<div class="form-group">
<label>Phone number (optional)</label>
<input type="text" id="tel" name="tel" />
</div>
</div>

Insert not working correctly in codeigniter

I am trying to insert data into the database and my code does add a new row but all the values are null. I don't know what's causing it. The view is inside a modal in html. Here's my code: Thanks for your help
Controller:
public function addItem(){
$save = array(
'inventoryID' => $this->input->post('rfid'),
'masterCode' => $this->input->post('masterCode'),
'itemName' => $this->input->post('itemName'),
'colorName' => $this->input->post('colorName'),
'location' => $this->input->post('location'),
'itemCategory' => $this->input->post('itemCategory'),
'materialDescription' => $this->input->post('materialDescription'),
'supplier' => $this->input->post('supplier'),
'itemDescription' => $this->input->post('itemDescription'),
'comments' => $this->input->post('comments'),
'itemCode' => $this->input->post('itemCode'),
'colorCode' => $this->input->post('colorCode')
);
$this->searchModel->form_insert($save);
//load the header
$this->load->view('base.php',$save);
//load the page
redirect('Search');
//load the footer
$this->load->view('footer.php',$save);
}
Model:
function form_insert($data){
// Inserting in Table(inventory) of Database(library)
$this->load->database();
$this->db->insert('inventory', $data);
$inventoryID = $this->db->insert_id();
}
View:
<div id="addItem" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form method ="post" action= "<?php echo site_url("Search/addItem"); ?>">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add an Item</h4>
</div>
<div class="modal-body">
<form role="form">
<table>
<tr>
<td><input type="text" name="rfid" placeholder="RFID" required/></td>
<td><input type="text" name="itemCode" placeholder="Item Code" required/></td>
<td><input type="text" name="masterCode" placeholder="Master Code" /></td>
</tr>
<tr>
<td><input type="text" name="itemName" placeholder="Item Name" required/></td>
<td><input type="text" name="colorCode" placeholder="Color Code" /></td>
<td><input type="text" name="colorName" placeholder="Color Name" /></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Location" required/></td>
<td><input type="text" name="makelocation" placeholder="Location Made" required/></td>
<td><input type="text" name="itemCategory" placeholder="Item Category" /></td>
</tr>
<tr>
<td><input type="text" name="materialDescription" placeholder="Material Description" /></td>
<td><input type="text" name="supplier" placeholder="Supplier/Vendor" required/></td>
<td><input type="text" name="checkoutAllowed" placeholder="Checkout Allowed" /></td>
</tr>
</table>
<div class="row personal-info">
<div class="col-sm-4">
<div class="form-group">
<textarea name="itemDescription" placeholder="Insert information regarding the weather this item is suitable for and where it is used"></textarea>
<textarea name="Comments" placeholder="Additional Coments on the Item"></textarea>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer" style="text-align:center;">
<input class="btn btn-primary" name="addItem" value="Add Item">
</div>
</form>
</div>
</div>
</div>
The problem is that you do not actually "submit" the form data. Your button links to the correct controller/method but does not send any data to the controller when you use a link, i.e. <a href=.... You need a submit button.
The change is quite simple. Change the code for the button as follows.
<div class="modal-footer" style="text-align:center;">
<input type="submit" class="btn btn-primary" name="addItem" value="Add Item">
</div>
There is another issue. You have two <form> tags.
Remove the line
<form method ="post" action="<?php echo site_url("Search/addItem"); ?>">
And change the line
<form role="form">
to
<form method="post" action="<?php echo site_url("Search/addItem"); ?>" role="form">
You also need to remove the extra form close tag two lines above the button's code. Nested <form>s are not allowed. And you need to move the closing tag for <div class="modal-content"> So to make it more clear here is what your view should finally look like.
<div id="addItem" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add an Item</h4>
</div>
<div class="modal-body">
<form method ="post" action= "<?php echo site_url("Search/addItem"); ?>" role="form">
<table>
<tr>
<td><input type="text" name="rfid" placeholder="RFID" required/></td>
<td><input type="text" name="itemCode" placeholder="Item Code" required/></td>
<td><input type="text" name="masterCode" placeholder="Master Code" /></td>
</tr>
<tr>
<td><input type="text" name="itemName" placeholder="Item Name" required/></td>
<td><input type="text" name="colorCode" placeholder="Color Code" /></td>
<td><input type="text" name="colorName" placeholder="Color Name" /></td>
</tr>
<tr>
<td><input type="text" name="location" placeholder="Location" required/></td>
<td><input type="text" name="makelocation" placeholder="Location Made" required/></td>
<td><input type="text" name="itemCategory" placeholder="Item Category" /></td>
</tr>
<tr>
<td><input type="text" name="materialDescription" placeholder="Material Description" /></td>
<td><input type="text" name="supplier" placeholder="Supplier/Vendor" required/></td>
<td><input type="text" name="checkoutAllowed" placeholder="Checkout Allowed" /></td>
</tr>
</table>
<div class="row personal-info">
<div class="col-sm-4">
<div class="form-group">
<textarea name="itemDescription" placeholder="Insert information regarding the weather this item is suitable for and where it is used"></textarea>
<textarea name="Comments" placeholder="Additional Coments on the Item"></textarea>
</div>
</div>
</div>
<div class="modal-footer" style="text-align:center;">
<input type="submit" class="btn btn-primary" name="addItem" value="Add Item">
</div>
</form>
</div>
</div>
</div>
</div>

How change the format of full calendar

I want to change the format of date which is showing on text box after choosing dates. I tried format table and other coding found in Google but it doesn't work.
<form action="report_emp.php" method="post">
<input name="id" type="hidden" value="<?php echo $_GET['id'];?>">
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<tbody>
<tr>
<td>From</td>
<td>
<div class="control-group">
<label class="control-label" for="date01">Date</label>
<div class="controls">
<input type="text" class="input-xlarge datepicker" id="date01" name="datefrom" value="mm/dd/yy">
</div>
</div>
</td>
<td>To</td>
<td>
<div class="control-group">
<label class="control-label" for="date02">Date</label>
<div class="controls">
<input type="text" class="input-xlarge datepicker" id="date02" name="dateto" value="mm/dd/yy">
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Find Client Details</button>
<button class="btn">Cancel</button>
</div>
</form>
If you are talking about jquery datepicker, then you can use:
$( "#datepicker" ).datepicker( "option", "dateFormat", "mm/dd/yy" );
Check here.

Dynamic form field with jquery not post values to php

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.

Categories