The problem is here that I have successfully written the code to add and remove row on checked checkbox but it only works for the first element.
Like when I click on the first element it adds a row and on unchecking it remove that row second time when I check and uncheck the second checkbox it adds a row on checked and removes row on unchecked.
here is jquery code
<script type="text/javascript">
$(document).ready(
function () {
$('.finding').change(
function () {
if ($('.finding').is(':checked')) {
var finding = $(this).next('label').text();
$('#findings-table').append("<tr><td>"+finding+"</td></tr>");
}
else {
$('#findings-table').empty();
}
});
});
</script>
here is php code i'm getting checkboxes
if ($checkResult > 0) {
for ($i=0; $i < $checkResult ; $i++) {
$result = mysqli_fetch_assoc($query);
$findings = $result['name'];
$count = 1 + $i;
echo"<tr>
<th scope='row'>$count</th>
<td scope='col'>
<div class='input-group'>
<input class='finding form-check-input' type='checkbox' name='findings[]' value='$findings'>
<label class='input-label pt-1 px-3'>$findings</label>
</div>
</td>
</tr>";
}
}
and finally here is my html code where checkboxes appear
<div class='table-container' style="height: 21vh;">
<table class="table table-hover" style="line-height: 7px;">
<tbody>
<?php include 'getfindings.php'; ?>
</tbody>
</table>
</div>
I could not figure out what #findings-table is, therefor I just created a table.
See this:
$(function() {
$('.finding').on('change', function(e) {
var $this = $(e.currentTarget),
$findingTable = $('#findings-table'),
labelText = $this.parents('.input-group').find('.input-label').text();
if ($this.is(':checked')) {
$findingTable.append($('<tr/>').append($('<td/>').text(labelText)));
} else {
$findingTable.empty();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<table id="findings-table"></table>
<div class='table-container' style="height: 21vh;">
<table class="table table-hover" style="line-height: 7px;">
<tbody>
<tr>
<th scope='row'>1</th>
<td scope='col'>
<div class='input-group'>
<input class='finding form-check-input' type='checkbox' name='findings[]' value='a'>
<label class='input-label pt-1 px-3'>nice a</label>
</div>
</td>
</tr>
<tr>
<th scope='row'>2</th>
<td scope='col'>
<div class='input-group'>
<input class='finding form-check-input' type='checkbox' name='findings[]' value='b'>
<label class='input-label pt-1 px-3'>nice b</label>
</div>
</td>
</tr>
<tr>
<th scope='row'>3</th>
<td scope='col'>
<div class='input-group'>
<input class='finding form-check-input' type='checkbox' name='findings[]' value='c'>
<label class='input-label pt-1 px-3'>nice c</label>
</div>
</td>
</tr>
<tr>
<th scope='row'>4</th>
<td scope='col'>
<div class='input-group'>
<input class='finding form-check-input' type='checkbox' name='findings[]' value='d'>
<label class='input-label pt-1 px-3'>nice d</label>
</div>
</td>
</tr>
</tbody>
</table>
</div>
Related
So this is my order page and I want to add an option which prevents the user from leaving the quantity option empty. I cannot seem to use the required option as it compels the user to fill every box instead of the one just selected.
Here is the code
<body>
<?php include('navbar.php'); ?>
<div class="container">
<h1 class="page-header text-center">ORDER</h1>
<form method="POST" action="purchase.php">
<table class="table table-striped table-bordered">
<thead>
<th class="text-center"><input type="checkbox" id="checkAll"></th>
<th class="productheading">Category</th>
<th class="productheading">Product Image
<th class="productheading">Product Name</th>
<th class="productheading">Price</th>
<th class="productheading">Quantity</th>
</thead>
<tbody>
<?php
$sql = "select * from product left join category on category.categoryid=product.categoryid order by product.categoryid asc, productname asc";
$query = $conn->query($sql);
$iterate = 0;
while ($row = $query->fetch_array()) {
?>
<tr>
<td class="text-center"><input type="checkbox" value="<?php echo $row['productid']; ?>||<?php echo $iterate; ?>" name="productid[]" style=""></td>
<td><?php echo $row['catname']; ?></td>
<td><a href="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>"><img src="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>" height="170px" width="80%"></a></td>
<td class="productname1"><?php echo $row['productname']; ?></td>
<td class="price">Rs <?php echo number_format($row['price'], 2); ?></td>
<!-->**HERE IS THE CODE THAT NEEDS TO BE FIXED**--> <td><input type="number" class="form-control" name="quantity<?php echo $iterate; ?>"></td>
</tr>
<?php
$iterate++;
}
?>
</tbody>
</table>
<div class="row">
<div class="col-md-3">
<input type="text" name="customer" class="form-control" placeholder="Customer Name" required>
</div>
<div class="col-md-3">
<input type="number" name="number" class="form-control" placeholder="Contact Number" required>
</div>
<div class="col-md-2" style="margin-left:-20px;">
<button type="submit" onclick="myFunction()" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> Order</button>
<br />
<br />
<br />
</div>
</div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#checkAll").click(function() {
$('input:checkbox').not(this).prop('checked', this.checked);
});
});
</script>
</body>
</html>
You can target those fields with jQuery/JavaScript and make it required by focusing on it and then prevent the form from submitting. Try this
$(document).ready(function() {
$('#order-form').submit(function(e){
let $quantities = $(this).find('.table input[type="number"]').filter(function(){
return $(this).closest('tr').find('input[type="checkbox"]').is(':checked') && $(this).val() === '';
})
if( $quantities.length > 0 ){
e.preventDefault();
$quantities.first().focus()
}
})
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div class="container">
<form method="POST" action="purchase.php" id="order-form">
<table class="table table-striped table-bordered">
<thead>
<th class="text-center"><input type="checkbox" id="checkAll"></th>
<th class="productheading">Category</th>
<th class="productheading">Product Image
<th class="productheading">Product Name</th>
<th class="productheading">Price</th>
<th class="productheading">Quantity</th>
</thead>
<tbody>
<tr>
<td class="text-center"><input type="checkbox" value="1" name="productid[]" checked></td>
<td>Dishes</td>
<td><img src="https://via.placeholder.com/150/0000FF/FFFFFF?text=Bara" height="170px" width="80%"></td>
<td class="productname1">Bara</td>
<td class="price">Rs 79.00</td>
<td><input type="number" class="form-control" name="quantity[]"></td>
</tr>
<tr>
<td class="text-center"><input type="checkbox" value="1" name="productid[]"></td>
<td>Dishes</td>
<td><img src="https://via.placeholder.com/150/FF0000/FFFFFF?text=Chwela" height="170px" width="80%"></td>
<td class="productname1">Chwela</td>
<td class="price">Rs 120.00</td>
<td><input type="number" class="form-control" name="quantity[]"></td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> Order</button>
</form>
</div>
Answer in format requested by the OP
<body>
<?php include('navbar.php'); ?>
<div class="container">
<h1 class="page-header text-center">ORDER</h1>
<form method="POST" action="purchase.php" id="order-form">
<table class="table table-striped table-bordered">
<thead>
<th class="text-center"><input type="checkbox" id="checkAll"></th>
<th class="productheading">Category</th>
<th class="productheading">Product Image
<th class="productheading">Product Name</th>
<th class="productheading">Price</th>
<th class="productheading">Quantity</th>
</thead>
<tbody>
<?php
$sql = "select * from product left join category on category.categoryid=product.categoryid order by product.categoryid asc, productname asc";
$query = $conn->query($sql);
$iterate = 0;
while ($row = $query->fetch_array()) {
?>
<tr>
<td class="text-center"><input type="checkbox" value="<?php echo $row['productid']; ?>||<?php echo $iterate; ?>" name="productid[]" style=""></td>
<td><?php echo $row['catname']; ?></td>
<td><a href="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>"><img src="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>" height="170px" width="80%"></a></td>
<td class="productname1"><?php echo $row['productname']; ?></td>
<td class="price">Rs <?php echo number_format($row['price'], 2); ?></td>
<td><input type="number" class="form-control" name="quantity<?php echo $iterate; ?>"></td>
</tr>
<?php
$iterate++;
}
?>
</tbody>
</table>
<div class="row">
<div class="col-md-3">
<input type="text" name="customer" class="form-control" placeholder="Customer Name" required>
</div>
<div class="col-md-3">
<input type="number" name="number" class="form-control" placeholder="Contact Number" required>
</div>
<div class="col-md-2" style="margin-left:-20px;">
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> Order</button>
<br />
<br />
<br />
</div>
</div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#checkAll").click(function() {
$('input:checkbox').not(this).prop('checked', this.checked);
});
$('#order-form').submit(function(e){
let $quantities = $(this).find('.table input[type="number"]').filter(function(){
return $(this).closest('tr').find('input[type="checkbox"]').is(':checked') && $(this).val() === '';
})
if( $quantities.length > 0 ){
e.preventDefault();
alert("Quantity is required")
$quantities.first().focus()
}
})
});
</script>
</body>
In case of users who have disabled Javascript, you should also check on the server for missing quantities:
// purchase.php
if (isset($_POST['productid'])) {
for ( $i=0; $i < sizeof($_POST['productid']); $i++ ) {
if ( $_POST['productid'][$i] && ! $_POST['quantity'][$i] ) {
echo "Missing quantity for " . $_POST['productid'][$i] . "<br>";
}
}
}
I have a table reading out a few columns of a db, with an edit button in each row. All I am trying to do is, when the edit button is clicked, that row is displayed with all of its columns in another page. Any help would be great. I know it's simple, but I can get it to work. I am able to navigate to the next page, but not sure how to carry the id of the specific row and read that out. Thanks.
index. php
<form id="mainform" action="editFunding2.php">
<div class='row'>
<div class='col-12'>
<div class='table table-responsive'>
<table class='table table-striped table-bordered datatable active' id='grantTable'>
<thead>
<tr>
<th>FP ID</th>
<th>Short Title</th>
<th>PI</th>
<th>Department</th>
<th>Funding Type</th>
<th>Change Funding Type</th>
</tr>
</thead>
<tbody>
<?php
//Foreach loop iterates through each column of $getallrows function
foreach($allRows as $rowID => $rowInfo){ ?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
<!--Create dynamic id -->
<?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
<td>
<button type="submit" class="btn btn-danger" name="action" value='Change Funding Type'>Change Funding</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</form>
My editFunding2.php page
<div class='row'>
<div class='col-12'>
<div class='table table-responsive'>
<table class='table table-striped table-bordered datatable active' id='grantTable'>
<thead>
<tr>
<th>FP ID</th>
<th>Short Title</th>
<th>PI</th>
<th>Department</th>
<th>Division</th>
<th>Sponsor Name</th>
<th>Project Start</th>
<th>Project End</th>
<th>Funding Type</th>
<th>Yes/No</th>
<th>Proper Type If No</th>
<!-- <th>Exclusions</th>
<th>FP Durtation</th> -->
<th>Comment</th>
</tr>
</thead>
<tbody>
<?php
session_start();
$editRow = $_REQUEST['fpID'];
$mssql = mysqli_query("SELECT * FROM spacing.METADATA_WEBFORM WHERE FUNDING_PROPOSAL_ID = $fpID' ") or die (mysqli_error());
while($rowInfo = mysqli_fetch_array($mssql)) {
?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['Division'];?></td>
<td><?php echo $rowInfo['sponsorName'];?></td>
<td><?php echo $rowInfo['Date_Project_Start']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['Date_Project_End']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
<?php } ?>
<!--Create dynamic id -->
<?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
<td>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class='form-check-input' name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="Yes" id="rdYes" onclick="disable('<?php echo $rdDrop;?>')" checked/> Yes
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input class='form-check-input' type="radio" name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="No" id="rdNo" onclick="enable('<?php echo $rdDrop;?>')"/> No
</label>
</div>
</td>
<td>
<div class="dropdown">
<select class='form-control' name="ddgrantGroup[<?php echo $rowInfo['fpID'];?>]" id="<?php echo $rdDrop;?>" disabled>
<option value=''>Select Proper Funding Type</option>
<option value="Corporate Sponsor">Corporate Sponsor</option>
<option value="Federal">Federal</option>
<option value="Foundation Selected">Foundation Selected</option>
<option value="Internally Funded">Internally Funded</option>
<option value="State/Local">State/Local</option>
</select>
</div>
</td>
<td>
<div class="comment">
<textarea class="form-control" aria-label="With textarea" name="grantComment[<?php echo $rowInfo['fpID'];?>]" id="grantComment" placeholder="Comments"></textarea>
</div>
</td>
</tr>
</tbody>
</div>
</div>
</div>
<div class='row'>
<div class='col-12 text-right'>
<button type="submit" class="btn btn-secondary formsubmitbttn" name="action" value='save'>Save</button>
<button type="submit" class="btn btn-primary formsubmitbttn" name="action" value='complete'>Complete and Save</button>
</div>
</div>
</div>
Change your button to a
My Link to xx
In editFunding2.php :
$editRow = $_GET['id'];
This question already has answers here:
jQuery sum rows adding all cells
(3 answers)
Closed 5 years ago.
Below is my table code with Add New button. Onclick Add New
button new row will create. In picture you can see this. User will
input debit and credit values at the end all debit values should be
calculate and sum should be display and same for the credit value. I
am using jQuery to create new row:
Jquery code:
<script type="text/javascript">
$("#add, .check ").click(function() {
$('#datatable-buttons tbody>tr:last')
.clone(true)
.insertAfter('#datatable-buttons tbody>tr:last').find('input').each(function(){
$(this).val('');
});
});
</script>
Html table code:
<table id="datatable-buttons" class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th>
<input type="checkbox" id="check-all" class="flat">
</th>
<th class="column-title">Account</th>
<th class="column-title">Debits</th>
<th class="column-title">Credits</th>
<th class="column-title">Description</th>
<th class="column-title">Name</th>
<th class="column-title no-link last"><span class="nobr">Action</span>
</th>
<th class="bulk-actions" colspan="7">
<a class="antoo" style="color:#fff; font-weight:500;">Bulk Actions ( <span class="action-cnt"> </span> ) <i class="fa fa-chevron-down"></i></a>
</th>
</tr>
</thead>
<tbody>
<tr class="even pointer">
<td class="a-center ">
<input type="checkbox" class="flat" name="table_records">
</td>
<td class=" "><select class="form-control" name="journalname">
<option>Choose option</option>
<?php
$sql = mysqli_query($conn,'SELECT * FROM `chartofaccounts`');
while ($row1 = mysqli_fetch_array($sql))
{?>
<option value="<?php echo $row1["name"];?>"><?php echo $row1["name"];?></option>
<?php }?>
</select></td>
<td class=""><input class="form-control" type="text" name="debit" ></td>
<td class=" "><input class="form-control" type="text" name="credit"></td>
<td class=" "><input class="form-control" type="text" name="descc"></td>
<td class=" "><input class="form-control" type="text" name="name"></td>
<td class=" last">View
</td>
</tr>
</tbody>
</table>
<button type="button" id="add">Add New</button>
Below image will give you clear understanding:
made you a simple example of how to calculate the sum from the input fields.
check snippet below or jsFiddle
add numbers to the 3 inputs, and then click on View , it will get the sum of the 3 input values.
var input = $("input"),
button = $("td.last a")
$(button).click(function () {
var sum = 0;
$(input).each(function() {
sum += Number($(this).val());
});
$(this).html(sum)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>
<input>
</td>
<td>
<input>
</td>
<td>
<input>
</td>
<td class=" last">View
</tr>
</table>
Hello I'm not quite sure where i have gone wrong with this code i am very new to ajax and i have half an idea about php.
I have looked at other questions but everyones doing it in different ways then i am.
I am calling data via ajax to modal from SQL
index.php
<?php
$connect = mysqli_connect("localhost","root","","testing");
$query = "SELECT * FROM employee";
$result = mysqli_query($connect, $query);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container" style="width:700px;">
<h3 align="center">Employee Onboarding</h3>
<br>
<div class="table-responsive">
<table class="table table-bordered">
<tr> <th width="70%">Employee Name</th> <th width="30%">View</th> </tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr> <td> <?php echo $row['Name']; ?> </td> <td> <input type="button" name="view" value="view" id="<?php echo $row['EmployeeID']; ?>" class="btn btn-info btn-xs view_data"> </td> </tr>
<?php
}
?>
</table>
</div>
</div>
</body>
</html>
<!-- Modal -->
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Employee Details</h4>
</div>
<div class="modal-body" id="employee_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
</div>
</div>
</div>
</div>
<!-- Modal -->
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var employee_id = $(this).attr("EmployeeID");
$.ajax({
url:"modal.php",
method:"POST",
data:{employee_id:employee_id},
success:function(data){
$('#employee_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
modal.php
<?php
if(isset($_POST['employee_id']))
{
$output = '';
$connect = mysqli_connect("localhost","root","","testing");
$query = "SELECT * FROM employee WHERE EmployeeID = '".$_POST["employee_id"]."'";
$result = mysqli_query($connect, $query);
$output .= '
<div class="table-responsive">
<table class="table table-bordered">';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr> <td width="30%"> <label> Name </label> </td> <td width="70%"> '.$row['Name'].' </td> </tr>
<tr> <td width="30%"> <label> Adress </label> </td> <td width="70%"> '.$row['Address'].' </td> </tr>
<tr> <td width="30%"> <label> Gender </label> </td> <td width="70%"> '.$row['Gender'].' </td> </tr>
<tr> <td width="30%"> <label> Position </label> </td> <td width="70%"> '.$row['Position'].' </td> </tr>
<tr> <td width="30%"> <label> Age </label> </td> <td width="70%"> '.$row['Age'].' </td> </tr>
<tr> <td width="30%"> <label> Added Time </label> </td> <td width="70%"> '.$row['AddedTime'].' </td> </tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>
Live/Testing Site
You should also post your ajax! You should append the result of your modal.php into the actual modal.
modal.php
$output .= '
<div class="table-responsive">
<table class="table table-bordered">';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr> <td width="30%"> <label> Name </label> </td> <td width="70%"> '.$row['Name'].' </td> </tr>
<tr> <td width="30%"> <label> Adress </label> </td> <td width="70%"> '.$row['Address'].' </td> </tr>
<tr> <td width="30%"> <label> Gender </label> </td> <td width="70%"> '.$row['Gender'].' </td> </tr>
<tr> <td width="30%"> <label> Position </label> </td> <td width="70%"> '.$row['Position'].' </td> </tr>
<tr> <td width="30%"> <label> Age </label> </td> <td width="70%"> '.$row['Age'].' </td> </tr>
<tr> <td width="30%"> <label> Added Time </label> </td> <td width="70%"> '.$row['AddedTime'].' </td> </tr>
';
}
$output .= "</table></div>";
echo $output;
}
In your ajax. Assuming you use jquery:
$.ajax({
type: 'POST',
url : 'modal.php',
cache: false,
success: function(data){
$('#target').html(data);
}
});
HTML
<div class="modal">
<div id="target"></div>
</div>
Hello i am creating a school management system and facing a little problem.
The problem is that i am having a complex form containing following fields in a table
I have a table fee structure in which i want to insert data.
having columns
id | classID | sectionID | feetypeID | must | amount | active
1 1 1 1 must 500 yes
2 1 1 2 optional 500 no
so how to create an array such that it uses above form to insert data in table.
Basically i want users to choose feetype they want to have for classes and set their amount and then choose classes they want to apply it for so an entry is created in database for each section and each feetype they select.
I don't know how to make controller and model for this but i have this code of view
View
<form class="form-horizontal" role="form" method="post">
<div class="box-body">
<div class="row">
<div class="col-sm-12">
<h3>Fee Types</h3><br>
<div id="hide-table">
<table id="example1" class="table table-striped table-bordered table-hover dataTable no-footer">
<thead>
<tr>
<th class="col-sm-2"><?=$this->lang->line('slno')?></th>
<th class="col-sm-2"><?=$this->lang->line('feetype')?></th>
<th class="col-sm-2"><?=$this->lang->line('amount')?></th>
<th class="col-sm-2"><?=$this->lang->line('must')?></th>
<th class="col-sm-2"><?=$this->lang->line('active')?></th>
<th class="col-sm-2"><input type="checkbox"> Select All</th>
</tr>
</thead>
<tbody>
<?php if(count($feetypes)) {$i = 1; foreach($feetypes as $feetype) { ?>
<tr>
<td data-title="<?=$this->lang->line('slno')?>">
<?php echo $i; ?>
</td>
<td data-title="<?=$this->lang->line('feetype_name')?>" name="feetypeID" value="<?php echo $feetype->feetypeID;?>">
<?php echo $feetype->feetype; ?>
</td>
<td data-title="<?=$this->lang->line('amount')?>" name="amount">
<input type="text" class="form-control" value="<?php echo $feetype->defaultamount; ?>">
</td>
<td data-title="<?=$this->lang->line('must')?>">
<select class="form-control" name="must">
<option value="MUST">Must</option>
<option value="OPTIONAL">Optional</option>
</select>
</td>
<td data-title="<?=$this->lang->line('active')?>">
<select class="form-control" name="active">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</td>
<td data-title="<?=$this->lang->line('select')?>">
<input type="checkbox" name="selected">
</td>
</tr>
<?php $i++; }} ?>
</tbody>
</table>
</div>
<div class="row">
<div class="col-sm-8">
<h3> Apply To</h3><br>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered table-striped">
<thead>
<th class="col-sm-3">Class</th>
<th class="col-sm-4">Section</th>
</thead>
<tbody>
<?php
foreach ($categories as $category)
{
?>
<tr>
<td> <input type="checkbox"><span style="font-size:18px;margin-left:10px;"> <?php echo $category->classes; ?></span>
</td>
<td>
<?php
if(!empty($category->subs)) {
foreach ($category->subs as $sub) {
echo "<input type='checkbox'> ".$sub->section.' ' ;
}
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<br><br>
<div class="form-group">
<div class="col-sm-12">
<input type="submit" class="btn btn-success" value="<?=$this->lang->line("add_feestructure")?>" >
</div>
</div>
</div>
</form>
Controller
public function addfeestructure(){
$usertype = $this->session->userdata("usertype");
if($usertype == "Admin" || $usertype == "Accountant"){
$this->data['categories'] = $this->feestructure_m->get_categories();
$this->data['feetypes'] = $this->feestructure_m->get_feetypes();
if($_POST){
}
$this->data['subview'] = "feestructure/addfeestructure";
$this->load->view('_layout_main', $this->data);
}
}
To submit multiple fields of the same name you need to add square brackets to your the name attribute like this; <input type="text" name="fieldName[]">.
Then in your controller you'll use a foreach loop to process the form:
public function submitForm() {
$fieldA = $this->input->post('fieldName'); // this will be an array
for ($i = 0; $i < sizeof($fieldA); $i++) {
$array = array('fieldA' => $fieldA[$i]);
$this->your_model->addRecordToDatabase($tableName, $array);
}
}