I've been searching all over and trying different combinations. I will try to explain exactly what I need. I have a table populated with SQL data, last column is an Edit button to open a bootstrap modal. I've been able to populate the table and create the edit button to pass the row id into the modal for the query on the modal populate all inputs with actual data on DB. Everything is working. But now I can't even make a POST on the form, I hit the button and nothing happens.
<?php
require 'style/header.php';
require 'core/db_connect.php';
?><div class="main">
<div class="row">
<table class= "table table-striped table-bordered table-hover">
<thead>
<tr>
<th colspan="1" rowspan="1" style="width: 180px;" tabindex="0">BI/CC</th>
<th colspan="1" rowspan="1" style="width: 220px;" tabindex="0">Name</th>
<th colspan="1" rowspan="1" style="width: 288px;" tabindex="0">Supplier Number</th>
<th colspan="1" rowspan="1" style="width: 40px;" tabindex="0">Actions</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT bicc, name, supplier_number ";
$query .= "FROM ext_work_risk ";
$result = sqlsrv_query($dbhandle, $query);
$i=0;
while($fetch = sqlsrv_fetch_array($result))
{
if($i%2==0) $class = 'even'; else $class = 'odd';
echo'<tr class="'.$class.'">
<td>'.$fetch['bicc'].'</td>
<td>'.$fetch['name'].'</td>
<td>'.$fetch['supplier_number'].'</td> <td><a class="modalButton" data-bicc="'.$fetch['bicc'].'"><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#modal_edit" data-container="body">Edit</button></a></td>
</tr>';
}
?>
</tbody>
</table>
</div>
</div>
<div id="modal_edit" class="modal fade" style="font-weight: normal;">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
<?php require 'style/footer.php' ?>
<!-- Script Part -->
<script type="text/javascript">
$('.modalButton').click(function(){
var bicc = $(this).attr('data-bicc');
$.ajax({url:"modal/ajax_ext_risk_modal_edit.php?bicc="+bicc,cache:false,success:function(result){
$(".modal-content").html(result);
}});
});
</script>
Now the "modal/ajax_ext_risk_modal_edit.php" file:
<?php
$bicc = $_GET['bicc'];
//DB connect settins
require '../core/db_connect.php';
$query = "SELECT * ";
$query .= "FROM ext_work_risk WHERE bicc='$bicc'";
$result = sqlsrv_query($dbhandle, $query);
$fetch = sqlsrv_fetch_array($result);
?>
<!-- Modal -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Co-Worker</h4>
</div>
<div class="modal-body">
<p>To edit just type the new date in the format <b>YYYY/MM/DD</b> and click save.
<form class="form-horizontal" role="form" method="POST" action="../core/process_ext_risk_modal.php">
<div class="form-group">
<label class="control-label col-sm-4">BI/CC:</label>
<div class="col-sm-7">
<input class="form-control" id="bicc" name="bicc" readonly="readonly" value="<?php echo $fetch['bicc']; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Name:</label>
<div class="col-sm-7">
<input class="form-control" id="name" readonly="readonly" value="<?php echo $fetch['name']; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Sup. Number:</label>
<div class="col-sm-7">
<input class="form-control" id="supplier_number" readonly="readonly" value="<?php echo $fetch['supplier_number']; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">LOTO:</label>
<div class="col-sm-7">
<input class="form-control" id="loto" name="loto" <?php $loto = $fetch['loto']->format('Y/m/d'); if ($loto == "2000/01/01") {echo "placeholder='Please insert date'";} else {echo "value='$loto'";} ?>>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Lift Platform:</label>
<div class="col-sm-7">
<input class="form-control" id="lift_platform" <?php $lift_platform = $fetch['lift_platform']->format('Y/m/d'); if ($lift_platform == "2000/01/01") {echo "placeholder='Please insert date'";} else {echo "value='$lift_platform'";} ?>>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-default btn-success" type="submit" name="submit" value="Submit">Save</button>
</div>
When I hit Save button nothing happens. Here is the ../core/process_ext_risk_modal.php file:
<?php
include("db_connect.php");
if(isset($_POST["save"])) {
$id = $_POST['bicc'];
$data = $_POST['loto'];
if(sqlsrv_query($dbhandle, "update ext_work_risk set loto='$data' where bicc='$id'"))
echo 'success';
}
?>
This last file is just for testing of course I will be Updating much more data on the form submit.
Thank you
I just found the problem thanks to Fred -ii tips:
So here is the previous code block:
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-default btn-success" type="submit" name="submit" value="Submit">Save</button>
</div>
And now the corrected one:
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button class="btn btn-default btn-success" type="submit" name="submit" value="Submit">Save</button>
</div>
</form>
Also changing if(isset($_POST["save"])) to if(isset($_POST["submit"])). Main problem being having submit outside form and two types defined on the same button.
Related
I am trying to pass data from an external query to a modal to be able to generate an update, but I notice that the variable of said query is not being passed to me, could you help me in what I am wrong, I am starting, my modal
<div id="content">
<button type="button" class="btn btn-danger" id= "hide" onclick="hide()">Close</button>
<form action="addcredits.php" method="POST" id="form1">
<input class="form-control" placeholder="Ingresa el total de efectivo" name="username" id="username">
<input type="button" name="btn" value="Ingresar" id="submitBtn" data-toggle="modal" data-target="#confirm-submit" class="btn btn-default" />
<div class="modal fade" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Confirmar
</div>
<div class="modal-body">
¿La cantidad ingresada es correcta?
<table class="table">
<tr>
<th>Efectivo</th>
<td id="uname"></td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input class="form-control" type="text" name="business_name" value="<?php echo $consult["id_students"]; ?>" placeholder="<?php echo $consul['id_students']; ?>">
<p><?php echo $consult["id_students"]; ?></p>
<p><?php echo $consult["id_students"]?></p>
Submit
</div>
</div>
</div>
</div>
</form>
and this is my extern consult
<?php
include("conection.php");
echo
'
<div class="container-fluid ">
<div class="row">
<div class="col-lg-12">
<table class="table table-hover">
<tr >
<th scope="col">Grupo</th>
<th scope="col">Nombre</th>
<th scope="col">Créditos</th>
</tr>
';
$accion = mysqli_real_escape_string($con,$_POST['accion']);
if($accion == 4)
{
$mi_busqueda = mysqli_real_escape_string($con,$_POST['mi_busqueda']);
$resultados = mysqli_query($con,"SELECT * FROM students WHERE
student_qr LIKE '%$mi_busqueda%'");
while($consult = mysqli_fetch_array($resultados))
{
echo
'
<tr >
<td>'.$consult["student_group"].'</td>
<td>'.$consult["student_name"]." " .$consult["student_secondname"]. " ". $consult["student_lastname"]. " ".'</td>
<td>'.$consult["student_credits"].'</td>
<td><button type="button" class="btn btn-warning" id= "show" onclick="show()" >Añadir Creditos</button></td>
</tr>
</div>
</div>
</div>
';
}
}
?>
I tried doing an echo but I don't see results, I suppose that the data remains from the external query, I don't know how I could generate said query on the same page by calling the modal instead of sending the data with javascript through JSON
The div appended value is not getting in controller but the appended thing is visible on the view page correctly and i had gone through several ways but couldn't reach to the correct point.
Here is my view section please have a look
<script type="text/javascript">
var maxAppends = 0;
function add_field(id)
{
var update_new = $('<div class="form-group" style="margin-bottom: 0px">\n\
<label for="field-1" class="col-sm-4 control-label">Documentsss</label>\n\
<div class="col-sm-5">\n\
<div class="fileinput fileinput-new" data-provides="fileinput">\n\
<span class="btn btn-default btn-file"><span class="fileinput-new" >Select file</span><span class="fileinput-exists" >Change</span><input type="file" name="files[]" ></span> <span class="fileinput-filename"></span>×</div></div>\n\<div class="col-sm-2">\n\<strong>\n\
<i class="fa fa-times"></i> Remove</strong></div>');
maxAppends++;
$(".update_new_"+id).append(update_new);
}
</script>
<div class=" table-responsive div1" id="EmpprintReport">
<table id="myTable" class="table table-bordered table-striped table2excel">
<thead>
<tr>
<th>Document Name</th>
<th>Documents</th>
<th>Number</th>
<th>Expiry Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if(!empty($details))
{
foreach ($details as $value) {
?>
<tr>
<td nowrap><?= $value->service_name;?></td>
<td nowrap>
<?php if (!empty($value->documents)): ?>
<div class="form-group">
<!-- <label class="col-sm-4 control-label"><?= ('Documents') ?>
: </label> -->
<div class="col-sm-8">
<?php
$uploaded_file = json_decode($value->documents);
if (!empty($uploaded_file)):
foreach ($uploaded_file as $sl => $v_files):
if (!empty($v_files)):
?>
<p class="form-control-static">
<a href="<?php echo base_url() . 'uploads/documents/' . $v_files; ?>"
target="_blank"
style="text-decoration: underline;"><?= $sl + 1 . '. ' . ('view') . ' ' . ('other_document') ?></a>
</p>
<?php
endif;
endforeach;
endif;
?>
</div>
</div>
<?php endif; ?>
</td>
<td nowrap><?= $value->service_number;?></td>
<td nowrap><?= $value->expiry_date;?></td>
<td>
<textarea id="<?php echo $value->id;?>" hidden> <?php echo $value->documents;?></textarea>
<a href="" data-toggle="modal" data-target="#edit_<?php echo $value->id;?>" id="Button3" id="Button3" class="btn btn-sm btn-warning" style="margin-top:5px;">
<i class="far fa-edit text-white" title="Edit"></i></a>
<a data-toggle="modal" data-target="#confirm_delete" name="delete" id="title" c-d-id="<?php echo $value->id;?>" clientid="<?= $id; ?>" class="btn btn-sm btn-danger deletedocument" style="margin-top:5px;">
<i class="fa fa-trash text-white" data-toggle="tooltip" data-placement="bottom" title="Delete"></i></a></td>
</tr>
<div class="modal fade edit" id="edit_<?php echo $value->id;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="padding:20px !important;">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Edit Document</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<?php
$result=$this->Admin_model->get_services_by_id($value->id);
//var_dump($value->id);
?>
<form method="post" class="form_<?php echo $value->id;?>" action="<?php echo base_url();?>admin/edit-client-registration-details/<?= $value->id; ?>/<?= $id; ?>" enctype="multipart/form-data">
<div class="form-group">
<div class="control-group">
<label>Service Name</label>
<input type="text" name="service_name" class="form-control" placeholder="Enter service name" style="width: 100%" value="<?= $value->service_name; ?>" /> </div>
<div class="control-group">
<label>Number</label>
<input type="text" name="service_no" class="form-control" placeholder="Enter number" style="width: 100%" value="<?= $value->service_number; ?>" />
</div>
<div class="control-group">
<label>Expiry Date</label>
<input type="text" name="date" id="date_<?= $value->id; ?>" class="form-control input-sm datepick" data-bind="datePicker: StartDate" value="<?= $value->expiry_date; ?>" />
</div>
<div id="update_new_<?php echo $value->id;?>" class="update_new_<?php echo $value->id;?> item-row">
<div class="form-group mb0" style="margin-bottom: 0px">
<label for="field-1"
class="col-sm-4 control-label">Other Document</label>
<div class="col-sm-5">
<div class="fileinput fileinput-new" data-provides="fileinput">
<?php
if (!empty($value->documents)) {
$uploaded_file = json_decode($value->documents);
}
if (!empty($uploaded_file)):foreach ($uploaded_file as $v_files_image): ?>
<div class="">
<input type="hidden" name="fileName[]"
value="<?php echo $v_files_image ?>">
<span class=" btn btn-default btn-file">
<span class="fileinput-filename"> <?php echo $v_files_image ?></span>
×
</span>
<strong>
<a href="javascript:void(0);" class="RCF"><i
class="fa fa-times"></i> Remove</a></strong>
<p></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
<!-- Here i want the appended result and the result is coming but the values selected here is not passing to the controller while submitting-->
</div>
<div id="msg_pdf" style="color: #e11221"></div>
</div>
<div class="col-sm-3">
<strong><a href="javascript:void(0);" id="update_more" onclick="add_field('<?php echo $value->id;?>');" u_id="<?php echo $value->id;?>" class="addCF item-row-click update_more"><i
class="fa fa-plus"></i> Add More
</a></strong>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<img src="<?php echo base_url();?>assets/resources/ajax-loader.gif" id="ajaxIndicator" style="display: none; margin-right: 10px" />
<input type="submit" id="btnSubmit" class="btn btn-primary" style="font-weight: bold" value="Edit Details" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</form>
</div>
</div>
</div>
</div>
<?php
}
}
?>
</tbody>
<tfoot>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
</div>
I have this AJAX code that will insert data to my CRUD table. But when I click the button that will save/insert the data to my table it will not show. All I want here is to insert my data using AJAX to my table without refreshing or using the form element in html.
Here is my code with my modal and the body of my table:
$(document).ready(function() {
// Add
$('#btn_add').click(function() {
var id = $('#brand_id').val();
var bname = $('#bname').val();
var bstatus = $('#bstatus').val();
$.ajax({
url: 'add_brand.php',
method: 'POST',
data: {
bname: bname,
bstatus: bstatus
},
success: function(data) {
$('#' + id).children('td[data-target=brand_name]').text(bname);
$('#' + id).children('td[data-target=brand_status]').text(bstatus);
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal fade" id="modal-default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Add a brand</h4>
</div>
<div class="modal-body">
<input type="hidden" id="brand_id" />
<div class="form-group">
<label for="bname">Brand Name</label>
<input type="text" class="form-control" id="bname" name="bname" placeholder="Brand Name" />
</div>
<div class="form-group">
<label for="bstatus">Status</label>
<select class="form-control select2" style="width: 100%;" id="bstatus" name="bstatus">
<option>Available</option>
<option>Not Available</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="btn_add">Save Changes</button>
</div>
</div>
</div>
</div>
<tbody>
<?php
include("db_connect/connect.php");
$query = mysqli_query($con, "SELECT * FROM brand");
while ($row = mysqli_fetch_array($query)) { ?>
<tr id="<?php echo $row['brand_id']; ?>">
<td data-target="brand_name"><?php echo $row["brand_name"]; ?></td>
<td data-target="brand_status"><?php echo $row["brand_status"]; ?></td>
<td>
<a data-role="edit" data-id="<?php echo $row['brand_id']; ?>" class="btn btn-success"><i class="fa fa-edit"></i> Edit</a>
<i class="fa fa-trash-o"></i> Delete
</td>
</tr>
<?php
}
?>
</tbody>
I'm having a modal on the receipt of every tenant on a table. The modal has a keyup function to calculate for its bill. and the equation is doing just fine and the fetching of the values to be calculated is also fine, the problem is every time i calculate for the previous electricity consumption it only fetches one value on the database. I have added the code on how i fetch from the database.
here is the Modal:
<div class="modal fade" id="receipt<?php echo $value['tenant_id'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form action="save_receipt.php" method="POST">
<input type = "hidden" class="form-control" name= "id" value = "<?php echo $value['tenant_id'];?>">
<div class="form-group">
<strong>
<div class= "modal-body2"><h3 class="modal-title text-center" id="myModalLabel">
<strong>Republic of the Philippines<br>Province of Negros Occidental
</strong></h3>
<h4 class ="text-center"><em>City of Victorias</em></h4>
<h4 class="text-center">
<strong>OFFICE OF THE MARKET SUPERVISOR
</strong>
</h4>
<br>
<div class="form-group">
<label class="col-sm-2 control-label">Name </label>: <?php echo $value['tenant_fname']." ".$value['tenant_mname']." ".$value['tenant_lname'];?>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Location </label>: Stall No. <?php echo $value['stall_number']." (".$value['stall_floor'];?>)
</div>
<div class="form-group">
<label class="col-sm-2 control-label">SUBJECT </label> :
FOR PAYMENT OF ELECTRICAL CONSUMPTION FOR THE PERIOD FROM
<input class = "datepick custom-input1"></input>
,TO
<input class = "datepick custom-input1"></input>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">METER NO. </label>: <input type="text" name="" class = "custom-input"></input>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">ELECTRIC RATE </label>:<input class = "custom-input3" value="<?php echo $value['elec_rate']?> per kWh" id= "rate" readonly ></input>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">PRESENT </label>: <input class = "custom-input" name="charges"></input>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">PREVIOUS </label>: <input class = "custom-input" value ="<?php echo $value['charges']?> kWh" id = "previous" readonly> </input>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">TOTAL CONSUMPTION</label>:
<input type="text" class = "custom-input" type="" id="result1" readonly>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">AMOUNT </label>:
<input type="text" class = "custom-input3" type="" id="result" value="" readonly>
</div><br>
<div class="form-group">
<p class="text-right">APPROVED BY:
<br>
<br>
LUDAISY B. FERNANDEZ <br>
MARKET SUPERVISOR III
</p>
</div>
</div>
</strong>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default close-modal" data-dismiss="modal">Close
</button>
<!-- <button type="submit" name="add" class="btn btn-primary">Save</button> -->
<button onclick="myFunction()" class="btn btn-primary">Print Receipt</button>
</div>
</form>
</div>
</div>
here is the script:
<script>
$('input[name="charges"]').on('change paste keyup', function(){
var a = $(this).val();
console.log(a);
var b = $('input#rate').val().replace('per kWh', '');
var c = $('input#previous').val().replace('kWh', '');
var subtotal = parseFloat(a - c);
var total = parseFloat(subtotal * b);
console.log(total);
$('input#result1').val(subtotal);
$('input#result').val(total);
});
$('.close-modal, .modal-fade').click(function(){
$('input#result1').val('');
$('input#result').val('');
$('input#charges').val('');
});
i have attached a example image of the receipt.
every time i input the current electricity consumption
it will automatically subrtract to the previous electricity consumption for the total consumption
and the total consumption will be multiplied to the rate for the amount to be paid.
as you can see the total consumption is giving a wrong answer because it is only fetching 1 value on the database.
here is how i fetch from the database:
<div class="panel-body">
<div class="dataTable_wrapper">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>Tenant</th>
<th>Stall Code</th>
<th>Previous Readings</th>
<th>Receipt</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM tenant
LEFT JOIN stall ON stall.stall_id = tenant.stall_id
LEFT JOIN rent ON rent.tenant_id = tenant.tenant_id
LEFT JOIN receipt ON receipt.tenant_id = tenant.tenant_id
LEFT JOIN rate ON rate.rate_id = tenant.rate_id
WHERE rent.rent_status = ? AND rate.rate_id = ?
";
$query = $conn->prepare($sql);
$query->execute(array(1,1));
$fetch = $query->fetchAll();
foreach ($fetch as $key => $value) { ?>
<tr>
<td><?=$value['tenant_fname']." ".$value['tenant_mname']." ".$value['tenant_lname'];?></td>
<td><?=$value['stall_number'];?></td>
<td><?=$value['charges'];?></td>
<td class = "center" style = "text-align:center;">
<a href = "#receipt<?php echo $value['tenant_id'];?>" data-toggle="modal" class="btn btn-outline btn-xs btn-primary"> Make Receipt
</a>
</td>
</tr>
<?php include 'receipt_modal.php';?>
<?php }?>
</tbody>
</table>
</div>
I am trying to make a script, to send PM to user which is selected from MySQL.
I have users list:
http://i.stack.imgur.com/9fRZV.png
When I click PM button, I get Javascipt sceen:
http://i.stack.imgur.com/4bJ9A.png
How to fill-in Javascript screen fields with values from users list automatically and send values to other PHP file (with AJAX)?
Code of users list table:
<!-- Table -->
<table class="table table-condensed">
<tr class="bg_h">
<th>Username</th>
<th>Email</th>
<th>Rank</th>
<th>Active?</th>
<th>Registration date</th>
<th>IP</th>
<th>PM</th>
</tr>
<?php
$sql = "SELECT * FROM users ORDER BY user_id ASC";
$query = $dbh->prepare($sql);
$query->execute();
$list = $query->fetchAll();
foreach ($list as $row) {
?>
<tr class="">
<td><?php echo $row['user_name']; ?></td>
<td><?php echo $row['user_email']; ?></td>
<td>
<?php
PHP code of getting user rank.
?>
</td>
<td>
<?php
PHP code to chech is user active.
?>
</td>
<td>
<?php echo $row['user_registration_datetime']; ?>
</td>
<td>
<?php echo $row['user_registration_ip']; ?>
</td>
<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#send-pm">#PM</button>
<div class="modal fade" id="send-pm" tabindex="-1" role="dialog" aria-labelledby="send-pm-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="send-pm-label">Send personal message</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name" class="control-label">Receiver name</label>
<textarea style="height:35px;" name="name" id="name" class="form-control" ></textarea>
</div>
<div class="form-group">
<label for="email" class="control-label">Email</label>
<textarea style="height:35px;" name="email" id="email" class="form-control" ></textarea>
</div>
<div class="form-group">
<label for="message" class="control-label">Message</label>
<textarea style="height:250px;" name="message" id="message" class="form-control" ></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" id="submit" class="btn btn-primary">SEND</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php
}
?>
</table>
First of all, you don`t need a modal dialog for every row in table. Take it out from the for-each loop.
Also, add a class to every #PM button for easier selection. Aftewards, bind some actions to #PM button click event. Here is the code, be sure jquery is loaded.
foreach ($list as $row) {
?>
<tr class="">
<td><?php echo $row['user_name']; ?></td>
<td><?php echo $row['user_email']; ?></td>
<td>
<?php
//PHP code of getting user rank.
?>
</td>
<td>
<?php
//PHP code to chech is user active.
?>
</td>
<td>
<?php echo $row['user_registration_datetime']; ?>
</td>
<td>
<?php echo $row['user_registration_ip']; ?>
</td>
<td>
<button type="button" class="btn btn-primary data-grab-trigger" data-toggle="modal" data-target="#send-pm">#PM</button>
</td>
</tr>
<?php
}
?>
</table>
<div class="modal fade" id="send-pm" tabindex="-1" role="dialog" aria-labelledby="send-pm-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="send-pm-label">Send personal message</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name" class="control-label">Receiver name</label>
<textarea style="height:35px;" name="name" id="name" class="form-control" ></textarea>
</div>
<div class="form-group">
<label for="email" class="control-label">Email</label>
<textarea style="height:35px;" name="email" id="email" class="form-control" ></textarea>
</div>
<div class="form-group">
<label for="message" class="control-label">Message</label>
<textarea style="height:250px;" name="message" id="message" class="form-control" ></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" id="submit" class="btn btn-primary">SEND</button>
</div>
</div>
</div>
</div>
<script>
$(function (){
$('.data-grab-trigger').on('click', function (e) {
_email = $(this).closest('tr').find('td').eq(0).text(); //get user email from the row where button was clicked
_name = $(this).closest('tr').find('td').eq(1).text(); //get user name from the row where button was clicked
$("#email").val(_email);
$("#name").val(_name);
});
});
</script>