Show data based on modal click - php

I made a while loop for the data to be displayed in a table format, I prepared <a> when clicked it opens a modal.
I want to have each modal have more info on that specific data when clicked.
Here is how I prepared things:
<?php
$mysqli = new mysqli('localhost', 'mushref', 'Almadina1!', 'security_db')
or die('Dramatic Error: ' . mysqli_error($mysqli));
$selectquery = "SELECT * FROM cases_reports";
$query = mysqli_query($mysqli, $selectquery);
$nums = mysqli_num_rows($query);
while($res = mysqli_fetch_array($query)) {
?>
<tr>
<td class="name mb-0 text-sm"> <?php echo $res['cccEmployee']?> </td>
<td> <?php echo $res['irNumber']?> </td>
<td> <?php echo $res['caseType']?> </td>
<td> <?php echo $res['startDateTime']?> </td>
<td> <?php echo $res['endDateTime']?> </td>
<td>
<div class="dropdown">
<a class="btn btn-sm btn-icon-only text-light" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v"></i>
</a>
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
<a class="dropdown-item" href="#">Print PDF</a>
<a class="dropdown-item" href="#">Export Excel</a>
<a class="dropdown-item" href="#">Export Access</a>
</div>
</div>
</td>
</tr>
<div class="modal fade" id="modal-default" tabindex="-1" role="dialog" aria-labelledby="modal-default" aria-hidden="true">
<div class="modal-dialog modal- modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title" id="modal-title-default"> <?php echo $res['caseType']?> </h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?php
echo $res['caseType'];
?>
</div>
</div>
<?php }?> <!-- End php While -->
Of course, the modal shows the first data available, which in this case "accident". How can I show each data's info when the modal URL is clicked?

just call your modal programmatically from js and load/replace its corresponing data before showing modal.
<?php echo $res['caseType']?>
and in your js file :
$(document).ready(function(){
$("#modalLuncher").click(function(){
$("#modal-title-default").html('read from #modalLuncher data-* tag');
// $("#other-replacements") ;
$("#modal-default").modal();
});
});

I wanted to show the modal so I can Ajax edit the table.
Here what I did:
Script:
$(document).ready(function() {
// Append values in input fields
$(document).on('click', 'a[data-role=update]', function(){
var id = $(this).data('id');
var cccEmployee = $("#"+id).children('td[data-target=cccEmployee]').text();
var irNumber = $("#"+id).children('td[data-target=irNumber]').text();
var caseType = $("#"+id).children('td[data-target=caseType]').text();
var startDateTime = $("#"+id).children('td[data-target=startDateTime]').text();
var endDateTime = $("#"+id).children('td[data-target=endDateTime]').text();
//Append the variables
$('#cccEmployee').val(cccEmployee);
$('#IR_number').val(irNumber);
$('#case_type').val(caseType);
$('#startDate').val(startDateTime);
$('#endDate').val(endDateTime);
$('#caseId').val(id);
$('#reportsModal').modal('toggle');
});
//Create event to get data from fields and update.
$('#save_report_changes').click(function() {
var id = $('#caseId').val();
var cccEmployee = $('#cccEmployee').val();
var irNumber= $('#IR_number').val();
var caseType = $('#case_type').val();
var startDateTime = $('#startDate').val();
var endDateTime = $('#endDate').val();
$.ajax({
url: '/edit-report',
method: 'post',
data: {
id: id,
cccEmployee: cccEmployee,
irNumber: irNumber,
caseType: caseType,
startDateTime: startDateTime,
endDateTime: endDateTime
},
success: function(response) {
$("#"+id).children('td[data-target=cccEmployee]').text(cccEmployee);
$("#"+id).children('td[data-target=irNumber]').text(irNumber);
$("#"+id).children('td[data-target=caseType]').text(caseType);
$("#"+id).children('td[data-target=startDateTime]').text(startDateTime);
$("#"+id).children('td[data-target=endDateTime]').text(endDateTime);
$('#reportsModal').modal('toggle');
},
});
});
});
Then created a while loop in php to display the data + linking the edit button to the ajax:
<!-- Start PHP While -->
<?php
$mysqli = new mysqli('localhost', 'mushref', 'Almadina1!', 'security_db')
or die('Dramatic Error: ' . mysqli_error($mysqli));
if( isset($_POST['id']) ) {
$id = $_POST['id'];
$ccc_employee = $_POST['cccEmployee'];
$IR_number = $_POST['irNumber'];
$case_type = $_POST['caseType'];
$caseLocation = $_POST['caseLocation'];
$startDate = $_POST['startDateTime'];
$endDate = $_POST['endDateTime'];
$case_description = $_POST['caseDesc'];
$action_taken = $_POST['actionsTaken'];
$details = $_POST['caseDetails'];
$notes = $_POST['caseNotes'];
$recommendation = $_POST['caseRecommendation'];
// Query to update data
$result = mysqli_query($mysqli, "UPDATE cases_reports SET
cccEmployee='$ccc_employee',
irNumber='$IR_number',
caseType='$case_type',
caseLocation='$caseLocation',
startDateTime='$startDate',
endDateTime='$endDate',
caseDesc='$case_description',
actionsTaken='$action_taken',
caseDetails='$details',
caseNotes='$notes',
caseRecommendation='$recommendation'
WHERE id='$id'");
if( $result ) {
return "Data updated successfully";
}
}
$selectquery = "SELECT * FROM cases_reports";
$table = mysqli_query($mysqli, $selectquery);
$nums = mysqli_num_rows($table);
while($res = mysqli_fetch_array($table)) {
?>
<tr id="<?php echo $res['id']?>">
<td data-target="cccEmployee"> <?php echo $res['cccEmployee']?> </td>
<td data-target="irNumber"> <?php echo $res['irNumber']?> </td>
<td data-target="caseType"> <?php echo $res['caseType']?> </td>
<td data-target="startDateTime"> <?php echo $res['startDateTime']?> </td>
<td data-target="endtDateTime"> <?php echo $res['endDateTime']?> </td>
<td class="table-actions">
<a href="#" data-role="update" data-id="<?php echo $res['id']; ?>">
<i class="fas fa-edit"></i>
</a>
<!-- <a href="#!" class="table-action table-action-delete" data-toggle="tooltip" data-original-title="Delete product">
<i class="fas fa-trash"></i>
</a> -->
</td>
<td>
<div class="dropdown">
<a class="btn btn-sm btn-icon-only text-light" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v"></i>
</a>
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
<a class="dropdown-item" href="#">Print PDF</a>
<a class="dropdown-item" href="#">Export Excel</a>
<a class="dropdown-item" href="#">Export Access</a>
</div>
</div>
</td>
</tr>
<div class="modal fade" id="reportsModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal- modal-dialog-centered modal-" role="document">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title" id="modal-title-default"> Case Details </h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="case-data">
<div class="form-row">
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="cccEmployee">CCC Employee</label>
<input type="text" class="form-control" id="cccEmployee" name="cccEmployee">
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="IR_number">IR Number</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="IR_number">IR#</span>
</div>
<input type="number" class="form-control" name="IR_number" id="IR_number">
</div>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="case_type">Case Type</label>
<select class="form-control" name="case_type" id="case_type" data-toggle="select">
<option value="" disabled selected>Select Case Type</option>
<option value="Accident">Accident</option>
<option value="Theft">Theft</option>
<option value="Death">Death</option>
<option value="Harrasment">Harrasment</option>
<option value="badBehaviour">Bad Behaviour</option>
<option value="Drugs">Drugs</option>
<option value="Drunk">Drunk</option>
<option value="Fight">Fight</option>
<option value="Medical">Medical</option>
<option value="illegalEntry">Illegal Entry</option>
<option value="illegalWorker">Illegal Worker</option>
<option value="Fire">Fire</option>
<option value="Electric">Electric</option>
<option value="illegalHunting">Illegal Hunting</option>
<option value="oilLeak">Oil Leak</option>
<option value="petrolLeak">Petrol Leak</option>
<option value="Kidnapping">Kidnapping</option>
<option value="Blackmail">Blackmail</option>
<option value="Misunderstanding">Misunderstanding</option>
<option value="propertyDamage">Property Damage</option>
<option value="smoke_NoFire">Smoke, No Fire</option>
<option value="stuck_InElevator">Stuck in Elevator</option>
<option value="Scooter">Scooter</option>
<option value="Drifting">Drifting</option>
<option value="LostPerson">Lost Person</option>
<option value="Fraud_Forgery">Fraud/Forgery</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="caseLocation">Location</label>
<select class="form-control" name="caseLocation" id="caseLocation" data-toggle="select">
<option value="" disabled selected>Select Location</option>
<option value="Baylasun">Baylasun</option>
<option value="Baylasun Hotel">Baylasun Hotel</option>
<option value="AL-Waha">AL-Waha</option>
<option value="Al-Morooj">Al-Morooj</option>
<option value="Royal Green">Royal Green</option>
<option value="Beach Towers">Beach Towers</option>
<option value="Emmar Building">Emmar Building</option>
<option value="Industrial Area (East)">Industrial Area (East)</option>
<option value="Industrial Area (West)">Industrial Area (West)</option>
<option value="Hejaz Gate">Hejaz Gate</option>
<option value="Gate 3">Gate 3</option>
<option value="Marina 1">Marina 1</option>
<option value="Marina 2">Marina 2</option>
<option value="Marina 3">Marina 3</option>
<option value="Tala Garden">Tala Garden</option>
<option value="AL-Shorooq">AL-Shorooq</option>
<option value="Yam Beach">Yam Beach</option>
<option value="Sales Center">Sales Center</option>
</select>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="startDate">Start Date & Time</label>
<input class="form-control" type="datetime-local" name="startDate" id="startDate">
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="endDate">End Date & Time</label>
<input class="form-control" type="datetime-local" name="endDate" id="endDate">
</div>
</div>
<div class="col-md-12 mb-3">
<div class="form-group">
<label class="form-control-label" for="case_description">Case Description</label>
<textarea class="form-control" name="case_description" id="case_description" rows="3"></textarea>
</div>
</div>
<div class="col-md-12 mb-3">
<div class="form-group">
<label class="form-control-label" for="action_taken">Actions Taken</label>
<textarea class="form-control" name="action_taken" id="action_taken"></textarea>
</div>
</div>
<div class="col-md-12 mb-3">
<div class="form-group">
<label class="form-control-label" for="details">Details</label>
<textarea class="form-control" name="details" id="details"></textarea>
</div>
</div>
<div class="col-md-12 mb-3">
<div class="form-group">
<label class="form-control-label" for="notes">Notes</label>
<textarea name="notes" id="notes" class="form-control"></textarea>
</div>
</div>
<div class="col-md-12 mb-3">
<div class="form-group">
<label class="form-control-label" for="recommendation">Recommendations</label>
<textarea name="recommendation" id="recommendation" class="form-control"></textarea>
</div>
</div>
<input type="hidden" id="caseId" class="form-control"/>
</div>
</div>
<div class="modal-footer">
<button type="button" id="save_report_changes" class="btn btn-primary">Save changes</button>
</div>
<?php } //End php While

Related

Laravel PHP filter Drop down Search

need help with the dropdown filter. my task is to separate the active, deactivate, for approval, etc. employees. so I did was I created a dropdown list filter to avoid creating another data table for every status. please help me. thank you!!!
this the controller
public function index()
{
$user = DB::table("user_basic")
->leftjoin("user_status","user_status.status_id" , "=" , "user_basic.user_id")
->select("user_status.*", "user_basic.*")
->get();
$datatables = datatables::of($user);
return view("pages.Directory.index")->with("user",$user);
}
the index page
#extends('pages.main-content')
#section('css')
#include('layouts.datatables-css')
#endsection
#section('content')
<body class="bg-info">
<div class="container-fluid">
<div class="col-1">
<form action="{{url ('directory') }}" method="GET">
<div class="row">
<div class="form-group">
<h6>
<select id='status' name="status"class="form-control" style="width: 200px">
<option value = "ACTIVE">Active</option>
<option value = "APPROVED">Approved</option>
<option value = "DEACTIVATED">Deactivated</option>
<option value = "DENIED"> Denied</option>
<option value = "DISAPPROVED">Disapproved</option>
<option value = "FOR APPROVAL">For Approval</option>
<option value = "INCOMPLETE">Incomplete</option>
<option value = "STARTUP">Startup</option>
</select>
<div class = "column-md-4">
</h6>
<button type ="submit" class ="btn btn-light">Filter <i class ="bi bi-funnel"></i></button>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="row ">
<div class="col-12">
<div class="card-body">
<table class="table table-hover table-fw-widget " id="table4">
<thead>
<td>ID</td>
<td><b>Username</b></td>
<td><b>Name</b></td>
<td><b>Birthdate</b></td>
<td><b>Status</b></td>
<td class="Text-center"><b>---------</b></td>
</tr>
</thead>
<tbody>
#foreach ($user as $user)
<tr>
<td>{{$user->user_id}}</td>
<td>{{$user->user_xusern}}</td>
<td>
<?php
$arr = array($user->user_xfirstname,
$user->user_xmiddlename,
$user->user_xlastname);
echo join(" ",$arr);
?>
</td>
<td>{{$user->user_xbirthdate}}</td>
<td>{{$user->status_xtitle}}</td>
<td class="Text-center"><a href="#" id="' . $user->user_id . '" class="text-success mx-1 showIcon" data-bs-toggle="modal" data-bs-target="#showusermodal">
<i class="bi bi-eye-fill h5"></i></a>
<a href="#" id="' . $user->user_id . '" class="text-danger mx-1 deleteIcon">
<i class="bi-trash h5"></i></a>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
<div class="col-1"></div>
</div>
</form>
</div>
{{-- View modal start --}}
<div class="modal fade" id="showusermodal" tabindex="-1" aria-labelledby="ModalLabel" data-bs-backdrop="static" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="Uname">Employee Information</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="#" method="POST" id="showinfo" enctype="multipart/form-data">
#csrf
<div class="modal-body p-4 bg-light">
<div class="row">
<div class="col-sm">
<label for="fname">First Name</label>
<input type="text" name="fname" id="fname" class="form-control" readonly>
</div>
<div class="col-sm">
<label for="midname">Middle Name</label>
<input type="text" name="midname" id="midname" class="form-control" readonly>
</div>
<div class="col-sm">
<label for="lname">Last Name</label>
<input type="text" name="lname" id="lname" class="form-control" readonly>
</div>
</div>
<div class="row">
<div class="col-lg">
<label for="birthdate">Birthdate</label>
<input type="text" name="bdate" id="bdate" class="form-control" value="" readonly>
</div>
<div class="col-lg">
<label for="birthdate">Status</label>
<input type="text" name="status" id="status" class="form-control" value="" readonly>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" id="add_employee_btn" class="btn btn-primary">Add Employee</button>
</div>
</form>
</div>
</div>
</div>
{{-- view modal end --}}
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2#11"></script>
</body>
#endsection
#section('scripts')
#include('layouts.datatables-scripts')
<script type="text/javascript">
$(document).ready(function()
{
$('#table4').DataTable();
});
</script>
#endsection
enter code here
you can write your query but remove get() function from the end .
$user = DB::table("user_basic")
->leftjoin("user_status","user_status.status_id" , "=" , "user_basic.user_id")
->select("user_status.*", "user_basic.*");
then write this if statement and don't forget to customize the column where i called status.name with your column name
if (request()->filled('status') && request('status') !== null) {
$data = $data->where('status.name', request()->status);
}
then path $user to datatables;
you will get the result
$datatables = datatables::of($user);

How to show form action result in modal

i want to show my action result in modal, after submit button is clicked, i want modal popup show my action result...........................................................................
This is html form
<form class="g-py-15" id="submit-button" action="<?php echo base_url('cekongkir/cek_ongkir') ?>" method="POST" role="form">
<div class="row">
<div class="col-xs-12 col-sm-6 mb-4">
<div class="form-group u-select--v3 g-pos-rel g-brd-none g-brd-bottom g-brd-gray-light-v7 rounded-0 mb-0">
<center><label><strong>From</strong></label></center>
<select name="province_id" id="provincefrom" onchange="loadCityfrom()" class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4 g-brd-primary--hover rounded g-py-15 g-px-15" required="">
<?php
echo "<option value=''> Select Province</option>";
foreach ($province as $p) {
echo "<option value='$p->province_id'>$p->prov_name</option>";
}
?>
</select>
<div class="d-flex align-items-center g-absolute-centered--y g-right-0 g-color-gray-light-v6 g-color-lightblue-v9--sibling-opened g-mr-15">
<i class="hs-admin-angle-down"></i>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 mb-4">
<div class="form-group u-select--v3 g-pos-rel g-brd-none g-brd-bottom g-brd-gray-light-v7 rounded-0 mb-0">
<center><label><strong>To</strong></label></center>
<select name="province_id" id="provinceto" onchange="loadCityto()" class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4 g-brd-primary--hover rounded g-py-15 g-px-15" required="">
<?php
echo "<option value=''> Select Province</option>";
foreach ($province as $p) {
echo "<option value='$p->province_id'>$p->prov_name</option>";
}
?>
</select>
<div class="d-flex align-items-center g-absolute-centered--y g-right-0 g-color-gray-light-v6 g-color-lightblue-v9--sibling-opened g-mr-15">
<i class="hs-admin-angle-down"></i>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 mb-4" required="required">
<div class="form-group u-select--v3 g-pos-rel g-brd-none g-brd-bottom g-brd-gray-light-v7 rounded-0 mb-0" id="cityAreafrom" required="required">
<select class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4 g-brd-primary--hover rounded g-py-15 g-px-15" required>
<option value="">Select City</option>
</select>
<div class="d-flex align-items-center g-absolute-centered--y g-right-0 g-color-gray-light-v6 g-color-lightblue-v9--sibling-opened g-mr-15">
<i class="hs-admin-angle-down"></i>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 mb-4" required="required">
<div class="form-group u-select--v3 g-pos-rel g-brd-none g-brd-bottom g-brd-gray-light-v7 rounded-0 mb-0" id="cityAreato" required="required">
<select class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4 g-brd-primary--hover rounded g-py-15 g-px-15" required>
<option value="">Select City</option>
</select>
<div class="d-flex align-items-center g-absolute-centered--y g-right-0 g-color-gray-light-v6 g-color-lightblue-v9--sibling-opened g-mr-15">
<i class="hs-admin-angle-down"></i>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 mb-4" required="">
<div class="form-group u-select--v3 g-pos-rel g-brd-none g-brd-bottom g-brd-gray-light-v7 rounded-0 mb-0" required="required" id="subdistrictAreafrom">
<select class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4 g-brd-primary--hover rounded g-py-15 g-px-15" required>
<option value="">Select Subdistrict1</option>
</select>
<div class="d-flex align-items-center g-absolute-centered--y g-right-0 g-color-gray-light-v6 g-color-lightblue-v9--sibling-opened g-mr-15">
<i class="hs-admin-angle-down"></i>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 mb-4" required="">
<div class="form-group u-select--v3 g-pos-rel g-brd-none g-brd-bottom g-brd-gray-light-v7 rounded-0 mb-0" required="required" id="subdistrictAreato">
<select class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4 g-brd-primary--hover rounded g-py-15 g-px-15" required>
<option value="">Select Subdistrict</option>
</select>
<div class="d-flex align-items-center g-absolute-centered--y g-right-0 g-color-gray-light-v6 g-color-lightblue-v9--sibling-opened g-mr-15">
<i class="hs-admin-angle-down"></i>
</div>
</div>
</div>
</div>
<div class="mb-4">
<center><label>Berat Barang</label></center>
<center>
<div class="col-6">
<input class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4 g-brd-primary--hover rounded g-py-15 g-px-15" name="username" type="text" placeholder="(Kg)" required="">
</div>
</center>
</div>
<footer class="text-center">
<div class="col-12">
<button type="submit" class="btn btn-block u-btn-primary rounded g-px-30 g-py-11 ml-1" >Cari Ongkir</button>
</div>
</footer>
</form>
how to call the modal after form action calling action in controller
<script type="text/javascript">
function loadCityfrom(){
var province = $("#provincefrom").val();
$.ajax({
type:'GET',
url:"<?php echo base_url(); ?>register/cityList",
data:"province_id=" + province,
success: function(html)
{
$("#cityAreafrom").html(html);
}
});
}
function loadSubdistrictfrom(){
var city = $("#city").val();
$.ajax({
type:'GET',
url:"<?php echo base_url(); ?>register/subdistrictList",
data:"city_id=" + city,
success: function(html)
{
$("#subdistrictAreafrom").html(html);
}
});
}
</script>
<script type="text/javascript">
function loadCityto(){
var province = $("#provinceto").val();
$.ajax({
type:'GET',
url:"<?php echo base_url(); ?>register/cityListto",
data:"province_id=" + province,
success: function(html)
{
$("#cityAreato").html(html);
}
});
}
function loadSubdistrictto(){
var city = $("#cityto").val();
$.ajax({
type:'GET',
url:"<?php echo base_url(); ?>register/subdistrictListto",
data:"city_id=" + city,
success: function(html)
{
$("#subdistrictAreato").html(html);
}
});
}
</script>
[Here my codepen]
https://codepen.io/hasta2103/pen/qBZmvjL

How to submit a jQuery step form

hope all is well. I really really really do need help submitting a jQuery step wizard form. I did get a plugin to help but it does most of its functionalities in jQuery and not html.
At the moment i have:
- Created the database and necessary table
- Created html form using jquery steps
- Connected the form to the database
- Connected database to html table for display
This is my html code:
<div class="modal fade" id="pat_add_modal" tabindex="-1" role="dialog" aria-labelledby="add_patient_label">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="add_patient_label">Add New Patient</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<!-- PHP Form Processor -->
<?php
include 'db.php';
if(isset($_POST['submit'])){
$pat_sname = $_POST['pat_sname'];
$pat_fname = $_POST['pat_fname'];
$pat_gender = $_POST['pat_gender'];
$pat_dob = $_POST['pat_dob'];
$pat_phone = $_POST['pat_phone'];
$pat_email = $_POST['pat_email'];
$insurance_companies = $_POST['insurance_companies'];
$card_no = $_POST['card_no'];
$pat_allergies = $_POST['pat_allergies'];
$pat_history = $_POST['pat_history'];
$pat_address = $_POST['pat_address'];
$nok_name = $_POST['nok_name'];
$nok_phone = $_POST['nok_phone'];
$nok_email = $_POST['nok_email'];
$pat_dependants = $_POST['pat_dependants'];
$pat_work = $_POST['pat_work'];
$pat_work_address = $_POST['pat_work_address'];
$work_phone = $_POST['work_phone'];
$work_email = $_POST['work_email'];
$ins_sql = "INSERT INTO patients (surname, first_name, gender, dateofbirth, phone, email, insurance_co, insurance_card_no, allergies, medical_history, full_address, nok_name, nok_phone, nok_email, dependants, palce_of_work, work_full_address, work_phone, work_email) VALUES ('$pat_sname', '$pat_fname', '$pat_gender', '$pat_dob', '$pat_phone', '$pat_email', '$insurance_companies', '$card_no', '$pat_allergies', '$pat_history', '$pat_address', '$nok_name', '$nok_phone', '$nok_email', '$pat_dependants', '$pat_work', '$pat_work_address', '$work_phone', '$work_email')";
$run_sql = mysqli_query($conn, $ins_sql);
echo "insertion success";
}else{
echo "insertion failed";
}
?>
<div class="card-block wizard-content">
<form class="tab-wizard wizard-circle form-horizontal floating-labels" role="form" name"this" id"this" action="patients.php" method="post">
<!-- Step 1 -->
<h6><strong>Personal Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_sname" id="pat_sname" required><span class="bar"></span><label for="pat_sname">Surname :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_fname" id="pat_fname" required><span class="bar"></span><label for="pat_fname">First Name :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<select class="form-control p-0" name="pat_gender" id="pat_gender" required>
<option value=""></option>
<option value="M">Male</option>
<option value="F">Female</option>
</select><span class="bar"></span>
<label for="pat_gender">Gender :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="date" class="form-control" name="pat_dob" id="pat_dob" required><span class="bar"></span><label for="pat_dob">D.O.B :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="tel" class="form-control" name="pat_phone" id="pat_phone" required><span class="bar"></span><label for="pat_phone">Phone :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="email" class="form-control" name="pat_email" id="pat_email" required><span class="bar"></span><label for="pat_email">Email :</label>
</div>
</div>
</div>
</section>
<!-- Step 2 -->
<h6><strong>Health Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<select class="form-control p-0" name="insurance_companies" id="insurance_companies" required>
<option value=""></option>
<option value="AAR">AAR</option>
<option value="AIG">AIG</option>
<option value="Britam">Britam</option>
<option value="IAA">IAA</option>
<option value="ICEA">ICEA</option>
<option value="Goldstar">Goldstar</option>
<option value="Liberty">Liberty</option>
<option value="NIC">NIC</option>
<option value="Sanlam">Sanlam</option>
<option value="SWICO">SWICO</option>
<option value="UAP">UAP</option>
</select><span class="bar"></span>
<label for="insurance_companies">Insurance Co.</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="card_no" id="card_no" required><span class="bar"></span><label for="card_no">Insurance Card No.</label>
</div>
</div>
<div class="col-md-12">
<div class="form-group m-t-20">
<textarea class="form-control" rows="1" id="pat_allergies" required></textarea>
<span class="bar"></span>
<label for="pat_allergies">Allergies :</label>
</div>
</div>
<div class="col-md-12">
<div class="form-group m-t-20">
<textarea class="form-control" rows="1" id="pat_history" required></textarea>
<span class="bar"></span>
<label for="pat_history">Medical History :</label>
</div>
</div>
</div>
</section>
<!-- Step 3 -->
<h6><strong>Home Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_address" id="pat_address" required><span class="bar"></span><label for="pat_address">Full Address :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="nok_name" id="nok_name" required><span class="bar"></span><label for="nok_name">Next of Kin :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="tel" class="form-control" name="nok_phone" id="nok_phone" required><span class="bar"></span><label for="nok_phone">Phone :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="email" class="form-control" name="nok_email" id="nok_email" required><span class="bar"></span><label for="nok_email">Email :</label>
</div>
</div>
<div class="col-md-12">
<div class="form-group m-t-20">
<textarea class="form-control" rows="1" id="pat_dependants" required></textarea>
<span class="bar"></span>
<label for="pat_dependants">Dependants :</label>
</div>
</div>
</div>
</section>
<!-- Step 4 -->
<h6><strong>Work Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_work" id="pat_work" required><span class="bar"></span><label for="pat_work">Place of Work :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_work_address" id="pat_work_address" required><span class="bar"></span><label for="pat_work_address">Full Address :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="tel" class="form-control" name="work_phone" id="work_phone" required><span class="bar"></span><label for="work_phone">Phone :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="email" class="form-control" name="work_email" id="work_email" required><span class="bar"></span><label for="work_email">Email :</label>
</div>
</div>
</div>
</section>
</form>
</div>
</div>
</div>
</div>
</div>
and this my script:
$(".tab-wizard").steps({
headerTag: "h6"
, bodyTag: "section"
, transitionEffect: "fade"
, titleTemplate: '<span class="step">#index#</span> #title#'
, labels: {
finish: 'Finish'
},
onFinished: function (event, currentIndex) {
swal({
type: "success",
title: "Good Job!",
text: "You have successfully added a new patient.",
});
var form = $(this);
form.submit();
},
});
Below is my html table:
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-block">
<div class="table-responsive">
<!--<div class="col-md-12 align-self-center">
<button class="btn pull-right hidden-sm-down btn-danger m-l-5" id="deletebutton" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-delete"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-info m-l-5" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-pen"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-warning m-l-5" type="button" data-toggle="modal" data-target="#doc_view_modal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-information-outline"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-primary m-l-5" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-cash-multiple"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-success m-l-20" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-calendar-plus"></i></button></a>
</div> -->
<table id="patientstable" class="display nowrap table table-hover table-striped table-bordered m-t-20" width="100%" cellspacing="0">
<thead>
<tr>
<th class="text-center">ID</th>
<th>Surname</th>
<th>First Name</th>
<th class="text-center">D.O.B</th>
<th class="text-center" >Gender</th>
<th class="text-center">Phone</th>
<th style="width: 100px;"></th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM patients";
$run_sql = mysqli_query($conn,$sql);
while ($rows = mysqli_fetch_array($run_sql)){
echo '
<tr>
<td class="text-center">'.$rows['id'].'</td>
<td>'.$rows['first_name'].'</td>
<td>'.$rows['surname'].'</td>
<td class="text-center">'.$rows['dateofbirth'].'</td>
<td class="text-center">'.$rows['gender'].'</td>
<td class="text-center">'.$rows['phone'].'</td>
<td id="actionicons">
<a href="user_id='.$rows['id'].'" data-toggle="modal" data-target="#pat_view_modal"> <i class="mdi mdi-information-outline text-warning"></i>
</i>
<a href="#" data-toggle="tooltip" data-original-title="Delete"> <i class="mdi mdi-delete text-danger"></i>
</td>
</tr>
';}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
I am stuck at a point where now have to submit the form but i am unable to since i can't call/reference the finish submit using an name or id since i can't assign it one.
Please help. Thanks.
Brian Dx.
In your patients.php you can use:
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
instead of:
if(isset($_POST['submit']))
since you can't put a submit name in jquery steps.

how to display the selected values in edit form using hidden field

here i fetch all the datas from database and display in table format.after that i click the edit button means i want to show already what value given, that values i want to show in text box(),normal like text box means i can show values but option values means i can't show the selected values in that field
<!--Edit part function here-->
<script>
function show_edit_menu(id, t_name, state_id, city_id) {
$("#show_edit_menu").show();
$("#tid").val(id); //truck auto id
$("#tname").val(t_name); //Truck Name
$("#state").val(state_id); //state id
$("#city").val(city_id); //city id
}
</script>
<script>
function edit_menu() {
var name = $("#tname").val(); //truck name
var tid = $("#tid").val(); //truck Id
var state = $("#state").val(); //state
var city = $("#city").val(); //city
//var gender=$('input[name=egender]:checked', '#edit_form').val();//gender ethu check agirukunu pakarathu
console.log(name); //here i can get the name
console.log(state); // here i can't get the state name
$.ajax({
type: "POST",
url: "ajax_edit_pgs.php",
data: {
name: name,
tid: tid,
state: state,
city: city
},
success: function(data) {
console.log(data)
if (data == "success") {
//window.location = 'dashboard.php';
} else {
$('#espan-error').html('Failed to Enter the Location');
}
}
});
}
</script>
<div class="row">
<div class="col-lg-12">
<!-- Start jQuery Datatable -->
<div class="portlet" style="margin-bottom:0px;">
<div class="portlet-heading dark">
<div class="portlet-title">
<h4></h4>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="well white">
<table id="SampleDT" class="datatable table table-hover table-striped table-bordered tc-table">
<thead>
<tr>
<th data-class="expand">Truck Names</th>
<th data-hide="phone,tablet">State</th>
<th data-hide="phone,tablet">City</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM trucks WHERE status !='1' ORDER BY reg_date DESC";
$result = mysql_query($sql);
$cat=array();
while($row = mysql_fetch_array($result))
{
echo '<tr>
<td>'.$row["truck_name"].'</td>
<td>'.Getstate($row["state_id"]).'</td>
<td>'.Getcity($row["city_id"]).'</td>
<td class="col-medium center">
<div class="btn-group btn-group-xs ">
<a class="btn btn-inverse" style="cursor:pointer;" onclick="show_edit_menu(\''.$row["id"].'\',\''.$row["truck_name"].'\',\''.$row["state_id"].'\',\''.$row["city_id"].'\')"><i class="fa fa-edit icon-only"></i>Edit</a>
<a class="btn btn-danger" onclick="prmpt_deletemenu('.$row["id"].')"><i class="fa fa-times icon-only"></i>Delete</a>
</div>
</td>
</tr>';
}
?>
</tbody>
</table>
<p id="error" style="text-align: center;font-size: 14px;color: #f00;font-weight: bold;display:none;"></p>
</div>
<!-- End jQuery Datatable -->
<!-- END YOUR CONTENT HERE -->
</div>
</div>
<!--edit part here-->
<div class="portlet" id="show_edit_menu" style="display:none;">
<div class="portlet-heading dark">
<div class="portlet-title">
<h4>Edit Menu</h4>
</div>
<div class="portlet-widgets">
<a data-toggle="collapse" data-parent="#accordion" href="#f-3"><i class="fa fa-chevron-down"></i></a>
</div>
<div class="clearfix"></div>
</div>
<div id="f-3" class="panel-collapse collapse in">
<div class="portlet-body">
<form class="form-horizontal" role="form" id="edit_form" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="col-sm-2 control-label">Truck Name<span class="require">*</span></label>
<div class="col-sm-8">
<input type="text" class="form-control" value="" name="tname" id="tname">
<input type="hidden" class="form-control" value="" name="tid" id="tid">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">State<span class="require">*</span></label>
<div class="col-sm-8">
<select name="state" id="state" onchange="getCity(this.value);" class="form-control intro-form-fixer" required="" id="state" name="state" data-msg-required="Please enter your State" value="" aria-required="true">
<!--<option value="">Select State</option>-->
<?php
$sql = mysql_query("SELECT * FROM state_list");
while($row=mysql_fetch_assoc($sql)){
?>
<option value="<?php echo $row['id'];?>"><?php echo $row['state'];?></option>
<?php } ?>
</select>
<input type="hidden" id="state" name="state" value="" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">City<span class="require">*</span></label>
<div class="col-sm-8">
<select class="form-control intro-form-fixer city" autocomplete="off" name="city" id="city" style="width:100%;">
<option value="">Select Area</option>
</select>
<input type="hidden" id="city" name="city" value="" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="tcb">
<label>
<span id="espan-error" style="color:#f00;"></span>
</label>
</div>
</div>
</div>
<div class="form-actions">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-primary" onclick="edit_menu()">Submit</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
function Getstate($id)
{
$f="SELECT * FROM state_list WHERE id='$id'";
$rr=mysql_query($f);
while($row=mysql_fetch_array($rr))
{
$state = $row['state'];
}
return $state;
}
function Getcity($id)
{
$f="SELECT * FROM city_list WHERE id='$id'";
$rr=mysql_query($f);
while($row=mysql_fetch_array($rr))
{
$city = $row['city_name'];
}
return $city;
}

Can't get advanced search dropdown values to fill via PHP

I have an advanced form that looks like this:
I am using a template from Bootsnipp which contains my code, and am trying to adjust it - available here.
My method of doing search is to append values to specific URL parameters based on the search, and then further down in the PHP code, check if those parameters are blank or contain values, and then execute code which fetches auctions from a database.
Since I started playing around to do this, the "Filter By State" buttons are not filling in the states filters from the database (the only thing that appears is the blank option), and also my search buttons (with the eyeglass icons) have disappeared. No idea why as this was working before. Note I am using PDO. Here is HTML and PHP code for the filter section:
<!-- Page Content -->
<div class="container">
<!--This is the search bar-->
<div class="container">
<div class="row">
<div class="col-sm-12">
<!-- http://stackoverflow.com/questions/8476602/appending-get-parameters-to-url-from-form-action-->
<!--If this is a form it messes up the styling-->
<div method="get" class="input-group" id="adv-search" action="listings.php">
<input type="text" name="q" class="form-control"
placeholder="Search for auctions by name or description" value=""/>
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="filter">Sort By</label>
<select class="form-control" name="sort" value="by_lowest_time">
<!-- By default by lowest time remaining-->
<option value="by_lowest_time" selected>Lowest Time Remaining</option>
<option value="by_highest_time">Highest Time Remaining</option>
<option value="by_lowest_price">Lowest Price</option>
<option value="by_highest_price">Highest Price</option>
</select>
</div>
<div class="form-group">
<label for="filter">Filter by Category</label>
<?php
try {
$catsql = 'SELECT * FROM ebay_clone.Category';
$catq = $db->query($catsql);
$catq->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
<select class="form-control" name="cat">
<option value=""></option>
<!-- http://stackoverflow.com/questions/3078192/how-to-set-html-value-attribute-with-spaces-using-php-->
<?php while ($r = $catq->fetch()): ?>
<option
value="<?php echo str_replace(' ', '_', strtolower(htmlspecialchars($r['item_category']))); ?>"> <?php echo htmlspecialchars($r['item_category']) ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group">
<label for="filter">Filter by State</label>
<?php
try {
// error_reporting(E_ERROR | E_PARSE);
$statsql = 'SELECT * FROM ebay_clone.State';
$statq = $db->query($statsql);
$statq->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
<select class="form-control" name="state">
<!-- Blank option-->
<option value=""></option>
<?php while ($r = $statq->fetch()): ?>
<option value="<?php echo trimstr_replace(' ', '_', strtolower(htmlspecialchars($r['state']))); ?>"> <?php echo htmlspecialchars($r['state']) ?> </option>
<?php endwhile; ?>
</select>
</div>
<button type="button" value="search" class="btn btn-primary"><span
class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
</form>
</div>
</div>
<button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-search"
aria-hidden="true"></span></button>
</div>
</div>
</div>
</div>
</div>
</div>
Your while loop fills a $row variable
<?php while ($row = $statq->fetch()): ?>
But you are using $r to read it:
$r['state']
I have figured this out. It was to do with me changing my SQL statement and reassigning a new SQL statement to a new query. Also, I didn't need to refer to my database name, only the table within the database.
This works now:
<!--This is the search bar-->
<div class="container">
<div class="row">
<div class="col-sm-12">
<!-- http://stackoverflow.com/questions/8476602/appending-get-parameters-to-url-from-form-action-->
<!--If this is a form it messes up the styling-->
<div class="input-group" id="adv-search">
<form method='get' action='listings.php'>
<input type="text" name="q" class="form-control"
placeholder="Search for auctions by name or description" value=""/>
</form>
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="filter">Sort By</label>
<select class="form-control" name="sort" value="by_lowest_time">
<!-- By default by lowest time remaining-->
<option value="by_lowest_time" selected>Lowest Time Remaining
</option>
<option value="by_highest_time">Highest Time Remaining</option>
<option value="by_lowest_price">Lowest Price</option>
<option value="by_highest_price">Highest Price</option>
</select>
</div>
<!-- Item Category -->
<div class="form-group">
<label for="filter">Filter by Category</label>
<select class="form-control" id="item-category" name="cat"
class="form-control">
<option value="" selected disabled hidden>Please Select a Category
</option>
<?php $sql = 'SELECT * FROM Category';
foreach ($db->query($sql) as $row) { ?>
<option
value="<?php echo $row['item_category']; ?>"><?php echo htmlspecialchars($row['item_category']); ?></option>
<?php } ?>
</select>
</div>
<!-- Item State -->
<div class="form-group">
<label for="filter">Filter by State</label>
<select class="form-control" id="item-state" name="state"
class="form-control">
<option value="" selected disabled hidden>Please Select a
Condition
</option>
<?php $sql = 'SELECT * FROM State';
foreach ($db->query($sql) as $row) { ?>
<option
value="<?php echo $row['state']; ?>"><?php echo htmlspecialchars($row['state']); ?></option>
<?php } ?>
</select>
</div>
<button type="submit" action="listings.php" method="get" value="search"
class="btn btn-primary"><span
class="glyphicon glyphicon-search" aria-hidden="true"></span>
</button>
</form>
</div>
</div>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"
aria-hidden="true"></span></button>
</div>
</div>
</div>
</div>
</div>
</div>

Categories