JezK
Edit File: branches.php
<?php include "sidemenu-start.php"; include "app/adminObject.php"; ?> <div class="container-fluid"> <div class="row"> <div class="col-md-6"> <h1>Branch</h1> </div> <div class="col-md-6 text-end"> <button type="button" data-bs-toggle="modal" data-bs-target="#addBranch" class="de-btn-small">Add Branch</button> </div> </div> <div class="row mt-3"> <div class="col-md-6 offset-md-6"> </div> </div> <div class="row mt-3"> <div class="col-md-12"> <table class="table" id="brachTable"> <thead> <tr> <th>S.no</th> <th>Branch Name</th> <th>NO OF SUBADMINS</th> <th>Created At</th> <th>Actions</th> </tr> </thead> <tbody> <!-- Table content goes here --> </tbody> </table> </div> </div> </div> <!-- Modal --> <div class="modal fade" id="addBranch" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content de-modal-content"> <form id="newBranch"> <div class="modal-header de-mh"> <h5 class="modal-title" id="exampleModalLabel">Add Branch</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="mb-3"> <label for="name" class="form-label">Branch Name</label> <input type="text" class="form-control" name="name" id="name"> <p class="error name_error"></p> </div> </div> <div class="modal-footer"> <button type="submit" class="de-btn-small" onclick="return validateNewBrach()">Add</button> </div> </form> </div> </div> </div> <!-- Edit Modal --> <div class="modal fade" id="editBranch" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content de-modal-content"> <form id="editBrachForm"> <div class="modal-header de-mh"> <h5 class="modal-title" id="exampleModalLabel">Update Branch</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="mb-3"> <label for="name" class="form-label">Branch Name</label> <input type="text" class="form-control" name="name" id="editname" value=""> <input type="hidden" class="form-control" name="id" id="editid" value=""> <p class="error edit_name_error"></p> </div> </div> <div class="modal-footer"> <button type="submit" class="de-btn-small" onclick="return validateEditBrach()">Update</button> </div> </form> </div> </div> </div> <!-- Delete Modal --> <div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content de-modal-content"> <div class="modal-header de-mh"> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <h1 class="modal-title text-center" id="exampleModalLabel">Do You want to Delete?</h1> </div> <div class="modal-footer"> <button type="button" class="de-btn-small yes" name="submit" onclick="deleteBranch(this.value)" style="margin-right:50px">Yes</button> <button type="button" class="close-btn" data-bs-dismiss="modal">No</button> </div> </div> </div> </div> <?php include "sidemenu-end.php"; ?> <script> let datatable; $(document).ready(function() { datatable = $('#brachTable').DataTable({ "processing": true, //Feature control the processing indicator. "serverSide": true, //Feature control DataTables' servermside processing mode. //"order": [], //Initial no order. "searching": true, "iDisplayLength": 10, "orderable": false, "ajax": { "url": 'app/getBranches.php', "type": "POST", "dataType": "json", "dataSrc": function(jsonData) { return jsonData.data; } }, "language": { searchPlaceholder: "Search", "search": '<div class="form"><i class="fa fa-search"></i></div>', "paginate": { "previous": '<i class="angles fa fa-angle-left"></i>', "next": '<i class="angles fa fa-angle-right"></i>' } } }); }); </script> <script> $('#newBranch').submit(function(event) { event.preventDefault(); formData = $('#newBranch').serialize()+"&addBrach=yes"; $.ajax({ type: 'POST', url: 'app/branches.php', data: formData, success: function(data) { if (data == 1) { toastr.success('Branch Created'); datatable.draw(); } else { toastr.warning('Branch Exists'); } $('#addBranch').modal('toggle') document.getElementById("newBranch").reset(); } }) }) function getBranchDetailsId(id) { $.ajax({ url: 'app/branches.php', type: 'POST', data: { singleBranch: 'yes', id: id }, success: function(response) { data = JSON.parse(response) $('#editname').val(data.name); $('#editid').val(data.brach_id) } }) } $('#editBrachForm').submit(function(event) { event.preventDefault(); formData = $('#editBrachForm').serialize() + "&editBrach=yes"; $.ajax({ type: 'POST', url: 'app/branches.php', data: formData, success: function(data) { if (data == 1) { toastr.success('Branch Updated'); datatable.draw(); } else { toastr.warning('Branch Already Exist'); } $('#editBranch').modal('toggle') document.getElementById("editBrachForm").reset(); } }) }) function getBranchId(id) { $('.yes').val(id); } function deleteBranch(id) { console.log(id,'dfgsdfgdfgsdg') $.ajax({ url: 'app/branches.php', type: 'POST', data: { deleteBranch: 'yes', id: id }, success: function(response) { if (response == 1) { $('#deleteModal').modal('toggle'); datatable.draw(); toastr.success('Branch Deleted'); } else { $('#deleteModal').modal('toggle'); toastr.error('Unable to delete'); } } }) } </script>