I know this has been asked a lot but after looking up for this for like 6 hours I can say I've tried everything that with my current knowledge (which isn't much) I can understand so I decided to come here and ask for help from the pros :).
This button is also inside korisnik.php
<button href="#myModal1" type="submit" role="button" data-toggle="modal" data-id="<?php print $row['kime']?>" class="open-myModal1"><span class="glyphicon glyphicon-edit"/></button>
This up top is a button that when clicked opens a modal and should pass a value to it, but it doesn't. After looking through a lot of posts on the net I found out easiest way is to send the variable back through AJAX so I used this:
This is located in bottom part of korisnik.php
$(document).on("click", ".open-myModal1", function ()
{
var kime = $(this).data('id');
$(".modal-body #kime").val( kime );
$.post('korisnik.php', { 'kime': kime });
});
Using $kime = $_POST['kime']; print $kime; in korisnici.php doesn't show the value at all but using <input type="text" name="kime" id="kime" value=""/> does. Problem with the one that works is that I still don't have the value needed inside a variable and can't use it to make a query based on the sent value.
So my question is:
How to make this work with ajax so I can get the value with $_POST['kime']?
or
How can I save the value inside the input field inside a variable?
I hope I've been clear enough with my request. Either one of those works since I get what I want and that is a value saved inside a variable I can use for other things.
Thanks for any help.
EDIT: This is modal Code inside korisnik.php
<div class="modal fade" id="myModal1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<center><h4 class="modal-title">EDIT KORISNIKA</h4></center>
</div><!-- end header -->
<hr/>
<div class="modal-body">
<!--<input type="text" name="kime" id="kime" value=""/>-->
<input type='text' name='kime' id='kime' value=''/>
<form class="form-horizontal" action='korisnik.php' method="post">
<?php
$kime = $_POST['kime'];
$query = $db->prepare("SELECT * FROM korisnik WHERE kime = :kime");
$query-> execute(array(':kime' => $kime ));
$result = $query->fetch();
?>
<table class="table table-striped">
<tr><th style="vertical-align:middle"><center>Korisničko Ime</center></th><td><input readonly class="form-control" name="username" value="<?php print $result['kime'] ?>"id="username" type="text"></td></tr>
<tr><th style="vertical-align:middle"><center>Ime</center></th><td><input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)" name="name" id="name" value="<?php print $result['ime'] ?>" type="text"></td></tr>
<tr><th style="vertical-align:middle"><center>Prezime</center></th><td><input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)" name="surname" id="surname" value="<?php print $result['prezime'] ?>" type="text"></td></tr>
<tr><th style="vertical-align:middle"><center>E-Mail</center></th><td><input class="form-control" name="email" id="email" onkeydown="emailk(this)" onkeyup="emailk(this)" onblur="emailk(this)" onclick="emailk(this)" value="<?php print $result['email'] ?>" type="email"></td></tr>
<tr><th style="vertical-align:middle"><center>Kredit</center></th><td><input class="form-control" name="kredit" id="kredit" onkeydown="alpha(this)" onkeyup="alpha(this)" onblur="alpha(this)" onclick="alpha(this)" value="<?php print $result['kredit'] ?>" type="number"></td></tr>
</table>
</div><!-- end body-->
<hr/>
<div class="modal-footer">
<input type="submit" class="btn btn-success pull-left" name="editk" value="Spremi Promjene" />
</form>
<button class="btn btn-default pull-right" data-dismiss="modal" type="button">Odustani</button>
</div><!-- end footer -->
</div><!-- end modal-content -->
</div><!-- end modal-dialog -->
</div><!-- end modal -->
So in the end after hours of what seemed endless searching and reading I found the solution to this. Instead of sending a variable to modal and doing query inside modal I did query before modal and sent all the values I needed like this.
<script type="text/javascript">
$(document).on("click", ".open-myModal1", function ()
{
var kime = $(this).data('id');
var ime = $(this).data('ime');
var prezime = $(this).data('prezime');
var email = $(this).data('email');
var kredit = $(this).data('kredit');
$(".modal-body #username").val( kime );
$(".modal-body #name").val( ime );
$(".modal-body #surname").val( prezime );
$(".modal-body #email").val( email );
$(".modal-body #kredit").val( kredit );
});
</script>
and the button I used to open modal was like this.
<button href="#myModal1" role="button" data-toggle="modal" data-id="<?php print $row['kime']?>" data-ime="<?php print $row['ime']?>" data-prezime="<?php print $row['prezime']?>" data-email="<?php print $row['email']?>" data-kredit="<?php print $row['kredit']?>" class="open-myModal1"></button>
Modal code:
<div class="modal fade" id="myModal1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<center><h4 class="modal-title">EDIT KORISNIKA</h4></center>
</div><!-- end header -->
<hr/>
<div class="modal-body">
<form class="form-horizontal" action='korisnik.php' method="post">
<table class="table table-striped">
<tr><th style="vertical-align:middle"><center>Korisničko Ime</center></th><td><input readonly class="form-control" name="username" value=""id="username" type="text"></td></tr>
<tr><th style="vertical-align:middle"><center>Ime</center></th><td><input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)" name="name" id="name" value="" type="text"></td></tr>
<tr><th style="vertical-align:middle"><center>Prezime</center></th><td><input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)" name="surname" id="surname" value="" type="text"></td></tr>
<tr><th style="vertical-align:middle"><center>E-Mail</center></th><td><input class="form-control" name="email" id="email" onkeydown="emailk(this)" onkeyup="emailk(this)" onblur="emailk(this)" onclick="emailk(this)" value="" type="email"></td></tr>
<tr><th style="vertical-align:middle"><center>Kredit</center></th><td><input class="form-control" name="kredit" id="kredit" onkeydown="alpha(this)" onkeyup="alpha(this)" onblur="alpha(this)" onclick="alpha(this)" value="" type="number"></td></tr>
</table>
</div><!-- end body-->
<hr/>
<div class="modal-footer">
<input type="submit" class="btn btn-success pull-left" name="editk" value="Spremi Promjene" />
</form>
<button class="btn btn-default pull-right" data-dismiss="modal" type="button">Odustani</button>
</div><!-- end footer -->
</div><!-- end modal-content -->
</div><!-- end modal-dialog -->
</div><!-- end modal -->
Thanks to all who tried to help! Till next time!
I think you mistake in syntax. You should call it like this:
$.ajax({
type: "POST",
url: "korisnik.php",
data:
{
kime: kime
}
});
You are missing a closing curly brace on your on click function.
$.post('korisnik.php', { 'kime': kime });
Above post should also work.
Retrieve it in PHP as follow:
$kime = $_POST['kime'];
Related
I know there are lots of similar posts but nothing really helps me. I'm trying to run a PHP function in Bootstrap Modal with two parameters, one of the parameter is a row ID that needs to go from jQuery.
I can send it and display it in a div id but how can I convert this parameter for a PHP function?
jQuery
$(document).ready(function() {
$("a").click(function(){
var hrefs = $(this).attr("href");
$("#modal_form").attr('action',hrefs);
var ids = hrefs.split("=").pop();
$("#sid").html(ids);
});
});
Bootstrap Modal
<!-- Update Record Modal -->
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="updateModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="updateModalLabel">Update Translation</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="translation.php" id="modal_form" method="post">
<div class="modal-body">
<div id="sid"></div> /* I'm getting the right ID here*/
<?php selectedTranslation($dbh, $ids); ?> /*I need to run this function*/
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" name="update" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
php function
function getAllTranslationById($dbh, $id){
...
<?php
$sqlSelect = "SELECT * FROM xxxx";
$result = mysqli_query($dbh, $sqlSelect);
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><input type="text" class="form-control" value="<?php echo $row['swrd_text'] ?>" readonly="readonly"></td>
<td><input type="text" class="form-control" value="<?php echo $row['swrd_context'] ?>" ></td>
<td><img alt="Link" src="images/edit.png" title="Update this row"></td>
</tr>
<?php }?>
</table>
<?php }
php function
function selectedTranslation($dbh, $sid){
....
<?php
$sqlSelect = "SELECT * FROM xxxx ";
$result = mysqli_query($dbh, $sqlSelect);
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><input type="text" class="form-control" value="<?php echo $row['swrd_text'] ?>" readonly="readonly"></td>
<td><input type="text" class="form-control" value="<?php echo $row['swrd_context'] ?>" ></td>
</tr>
<?php }?>
</table>
<?php }?>
Its just impossible like the way you want
So what you can do instead?
Use Ajax.
<div class="modal-body">
<div id="sid"></div> /* I'm getting the right ID here*/
<div id="ajaxResult"></div>
</div>
// JS Codes
$(document).ready(function() {
$("a").click(function(){
var sid = ""; // set your `sid` here
$.ajax({
url: "/url_here", //url to your PHP page
type: "post",
data: {id: sid},
success: function(data) {
$("#ajaxResult").html(data); //result html
}
});
});
});
I created a modal form to update the record with storage field that has an option and have to be taken from another table but if storage data already exist in the database then show existing data.
I did this code but it cannot show existing data.
If I change the code for "storage" to : ABC then it can show existing data in database.
<?php
// to connect database
include '../connection/connect.php';
$query_storage = mysqli_query ($connect, "SELECT * from storage ORDER BY
storages ASC");
?>
//code for modal bootstrap
<div id="add_data_Modal" 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">Reagent Detail Information</h4>
</div>
<div class="modal-body">
<form method="post" id="insert_form">
<label>Storage</label>
<select class="form-control" name = "storage" id="storage" required >
<?php while($row = mysqli_fetch_assoc($query_storage)){?>
<option value="<?php echo $row['id_storage']; ?>">
<?php echo $row['storages']; ?></option>";
<?php }
?>
</select>
<br />
<label>Min Stock</label>
<input type="text" name="min_stock" id="min_stock" class="form-control" />
<br />
<input type="hidden" name="reagent_id" id="reagent_id" />
<input type="submit" name="insert" id="insert" value="Insert" class="btn btn-success" />
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#add').click(function(){
$('#insert').val("Insert");
$('#insert_form')[0].reset();
});
$(document).on('click', '.edit_data', function(){
var reagent_id = $(this).attr("id");
$.ajax({
url:"php/reagent_master/fetch.php",
method:"POST",
data:{reagent_id:reagent_id},
dataType:"json",
success:function(data){
$('#storage').val(data.storages);
$('#min_stock').val(data.min_stock);
$('#max_stock').val(data.max_stock);
$('#reagent_id').val(data.id_reagent_master);
$('#insert').val("Update");
$('#add_data_Modal').modal('show');
}
});
});
get data from database by stroge and then if record found with this storage show your error message. Storage already exists
I am trying to create a way to edit rows in my DataTable implementation. I'm using AdminLTE BootStrap.
In this iteration I have a button at the end of each row that launches a modal. I would like the button to populate the data in the modal and essentially fill out the form with the row data so that the user can make any changes and Post them again.
What I have below "works" in that it does update the form, however it is only picking the last item in the While loop of my PHP which makes sense.
How can I update the form with the correct data from the row where the Edit button was clicked? There has to be a way to send specific data without interrupting the loop to still show the data table.
Table call
<table id="buildTracker" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Tracker ID</th>
<th>INI</th>
<th>Owner</th>
<th>Entered By</th>
<th>Record ID</th>
<th>Record Name</th>
<th>Items</th>
<th>Feature</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>".$row["ID"]."</td><td>".$row["INI"]."</td><td>".
$row["Owner"]."</td><td>".
$row["EnteredBy"]."</td><td>".
$row["RecordID"]."</td><td>".$row["RecordName"]."</td><td>".
$row["Items"]."</td><td>".$row["Feature"]."</td><td>";
echo '<button type="button" id="edit" onclick="update()" class="btn btn-default" data-toggle="modal" data-target="#modal-default">';
echo 'Edit';
echo '</button>'.'</td>';
echo "</tr>";
echo '<script>
function update() {
document.getElementById("enteredBy").value="'.$row["EnteredBy"].'";
document.getElementById("ini").value="'.$row["INI"].'";
document.getElementById("recordID").value="'.$row["RecordID"].'";
}
</script>';
}
} else {
echo "0 results";
}
$conn->close();
?>
...
Modal and Form
<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">Default Modal</h4>
</div>
<div class="modal-body">
<form id="buildtrackerform" role="form" action="formSubmit.php" method="post">
<div class="box-body">
<div class="form-group">
<div class="row">
<div class="col-xs-5">
<label for=>Entered By</label>
<input type="text" class="form-control" name="enteredBy" id="enteredBy" placeholder="Entered By">
</div>
<div class="col-xs-2">
<label for="ini">INI</label>
<select onChange="setOwner(this)" style="text-transform: uppercase;" class="form-control select2" style="width: 100%;" name="ini" id="ini">
<option selected="selected" disabled="disabled">-Select-</option>
</select>
</div>
<div class="col-xs-5">
<label for="owner">Owner</label>
<input type="text" class="form-control" name="owner" id="owner" placeholder="Nemours Owner">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-6">
<label for="recordID">Record ID</label>
<input type="text" class="form-control" name="recordID" id="recordID" placeholder="Record ID">
</div>
<div class="col-xs-6">
<label for="recordName">Record Name</label>
<input type="text" class="form-control" name="recordName" id="recordName" placeholder="Record Name">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-12">
<label>Items</label>
<select multiple class="form-control select2" name="items[]" id="items[]" data-placeholder=" Type an item then press enter"
style="width: 100%;">
</select>
</div>
</div>
</div>
<!-- There are more fields - I removed them for the question -->
</div><!-- End Box Body -->
</div> <!-- End Modal Body -->
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
And just in case the DataTable script
<script>
$(function () {
$('#example1').DataTable()
$('#buildTracker').DataTable({
'paging' : true,
'lengthChange': true,
'searching' : true,
'ordering' : true,
'info' : true,
'autoWidth' : true
})
})
</script>
Any guidance is appreciated. Thanks!
Remove the onclick property of your button and then give it a class. Lets say tableButton for this example. Then modify your javascript:
$(function () {
$('#example1').DataTable()
var table = $('#buildTracker').DataTable({
'paging' : true,
'lengthChange': true,
'searching' : true,
'ordering' : true,
'info' : true,
'autoWidth' : true
});
$('.tableButton').click(function () {
var data = table.row( $(this).parents('tr') ).data();
// data now contains your row data, insert it where you like
})
})
EDIT
A couple of pointers for you. In your original code you should remove this bit as you are currently outputting it repeatedly for every row in your database:
echo '<script>
function update() {
document.getElementById("enteredBy").value="'.$row["EnteredBy"].'";
document.getElementById("ini").value="'.$row["INI"].'";
document.getElementById("recordID").value="'.$row["RecordID"].'";
}
</script>';
My original code snippet didn't include anything to handle the data, without seeing your table I can't be exact but within the $('.tableButton').click function the variable data will be an array containing the values for each column of your table on the row which the button was clicked. If you modify the function to look like this you will get the idea:
$('.tableButton').click(function () {
var data = table.row( $(this).parents('tr') ).data();
alert( 'First column is '+data[0]+' Second column is '+data[1] );
})
Once you have figured out which column goes where then you change the alert to some code which inserts the values in the relevant inputs on your form.
I used multiple data tags in this instance. I think it is similar to miknik's suggestion but not using the data() function.
Echo'd the following in the button's creation.
data-id="'.$row["ID"].'" data-enteredBy="'.$row["EnteredBy"].'"
Then threw this into the JS on the bottom
<script>
$('#modal-default').on('show.bs.modal', function (e) {
var rowID = $(e.relatedTarget).attr('data-id');
$(this).find('#rowID').val(rowID);
var enteredBy = $(e.relatedTarget).attr('data-enteredBy');
$(this).find('#enteredBy').val(enteredBy);
//pass multiple data with data()
});
</script>
i'm new to core php coding here i'm having doubt in calling a db value to bootstrap modal popup
<td class="bgimg"><?php echo $obj["service_name"]; ?></td>
this is a line used in my code to send "service_id" which from a table and it should be displayed in the modal popup, from there, user has to fill the text fields and it should be update to another table with the same id.
here is the code of modal popup
<div id="edit-modal" class = "modal fade" tabindex="-1" role="dialog" style="padding-top: 150px;" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" id="myModalLabel">Choose your slots</h4>
</div>
<div class="modal-body">
<p class="edit-content">service id:</p>
<form role="form1" name="loginform" method="post" class="login-form">
<div class="form-group">
<table align="center">
<tr>
<td colspan="2"><center>slot 1</center></td>
</tr>
<tr>
<td><input type="date" id="datePicker" name="slot1_dt"> </td>
<td><input type="time" name="slot1_tm"> </td>
</tr>
<tr>
<td colspan="2"><center>slot 2</center></td>
</tr>
<tr>
<td><input type="date" id="datePicker" name="slot2_dt"> </td>
<td><input type="time" name="slot2_tm"> </td>
</tr>
<tr>
<td colspan="2"><center><button type="submit" name="book" class="btn btn-default" value="book" style="font-size: 14px !important;">Book</button></center></td>
</tr>
</table>
<?php
if(isset($_REQUEST["book"]))
{
if($_REQUEST["book"])
{
$service_id=$_REQUEST["serv_id"];
$customer_id=$_REQUEST["cust_id"];
$slot1_dt=$_REQUEST["slot1_dt"];
$slot2_dt=$_REQUEST["slot2_dt"];
$slot1_tm=$_REQUEST["slot1_tm"];
$slot2_tm=$_REQUEST["slot2_tm"];
$slot1=$slot1_dt." ".$slot1_tm;
$slot1 = date("Y-m-d H:i:s",strtotime($slot1));
$slot2=$slot2_dt." ".$slot2_tm;
$slot2 = date("Y-m-d H:i:s",strtotime($slot2));
$insertqry="INSERT INTO `tblappointments`(`customer_id`, `service_id`, `preferred_slot1_date`, `preferred_slot2_date`) VALUES ('$customer_id','$service_id','$slot1','$slot2')";
mysqli_query($con, $insertqry) or die(mysqli_error($con));
}
}
?>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
it displays the result well but service_id is not passing to update it in the database
thanks in advance
use modal event listener,
$(document).ready(function(){
$('#edit-modal').on('show.bs.modal', function (e) {
var id = $(e.relatedTarget).attr('id');
alert(id);
$("#service_id").val(id);
});
});
and in modal in <form></form> add hidden input
<input type="hidden" id="service_id" name="serv_id" value="">
SideNote: Don't use $_REQUEST, instead use $_POST and escape the string.
$(document).on("click", "#upload_image", function () {
var myBookId = $(this).data('id');
$(".modal-body #activity_id___").val( myBookId );
console.log(myBookId);
// As pointed out in comments,
// it is superfluous to have to manually call the modal.
// $('#addBookDialog').modal('show');
});
<input type="hidden" name="activity_id___" id="activity_id___" value=""/>
I have a commenting system that sits within a Bootstrap Modal, all works fine in terms of pulling data from the database, and the ability to enter data. the problem is on Submit.
This below is my code for the submit.
$(document).ready(function(){
var form = $('form');
var submit = $('#submit');
form.on('submit', function(e) {
e.preventDefault();
$.ajax({
url: 'projectnoteuploads.php',
type: 'POST',
cache: false,
data: form.serialize(),
success: function(data){
console.log(data);
var item = $(data).hide().fadeIn(800);
$('.comment-block').append(item);
},
error: function(e){
alert(e);
}
});
});
});
myjobspage.php - this is the start of my modal on my main page, it's called from the Notes button
<div id="projnotes" class="modal fade modal-scroll" tabindex="-1" data-width="960">
</div>
I originally had the rest of the modal within the div above, but as I was having this issue of it closing the form and refreshing the page, I decided to move the modal onto another page, and have it called when the button is clicked, but still having the same issue
This is the modal code
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Project Notes</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<!-- Table shown here (no need to show as not involved) -->
</div>
</div>
<div class="row">
<div class="col-md-12">
<!--comment form -->
<form class="notesform" id="notesform" name="notesform" method="post">
<!-- need to supply post id with hidden fild -->
<input type="hidden" name="postid" value="<?php echo $propid; ?>">
<input type="hidden" name="projno" value="<?php echo $projectno; ?>">
<input type="hidden" name="name" value="<?php echo $inputby; ?>">
<div class="col-md-12 ">
<div class="form-group">
<label for="inputEmail12" class="col-md-2 control-label">Project Notes *</label>
<div class="col-md-8">
<textarea class="form-control col-md-8" rows="3" name="comment" id="comment"placeholder="Type your comment here...." required></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<br>
<input type="submit" class="btn green" id="savenotes" name="submit" value="Submit Comment" />
</div>
</div>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
</div>
One question on this though is that to call the jquery/Ajax code is done through my main page, is this right or should it be done through the page that the Model body is on?
When the Submit button id="savenotes" is clicked, the modal closes and refreshes the page losing all data within the main page.
How can I submit data to the database without the Modal closing?
I don't know if you've found an answer to this but at least for others who might need solutions just like I once did.
This is the modal page named modal.php:
<div id="projnotes" class="modal fade modal-scroll" tabindex="-1"
data-
width="960">
<!-- div wrapper for modal dialog -->
<div class="modal-dialog">
<!-- div wrapper for modal content -->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
hidden="true"></button>
<h4 class="modal-title">Project Notes</h4>
</div>
<!-- I guess you wanted your body centered .justify-content-center
should fix that -->
<div class="modal-body justify-content-center">
<div class="row">
<div class="col-md-12">
<!-- Table shown here (no need to show as not involved) -->
</div>
</div>
<!-- I guess you wanted your form centered .justify-content-center
would fix that -->
<div class="row justify-content-center">
<!--comment form -->
<form class="notesform form-block" id="notesform" name="notesform"
method="post" action="projectnoteuploads.php">
<!-- need to supply post id with hidden fild -->
<input type="hidden" name="postid" value="<?php echo $propid =
'propid'; //replace variable $propid ?>">
<input type="hidden" name="projno" value="<?php echo $projectno =
'projectno'; //replace variable $projectno ?>">
<input type="hidden" name="name" value="<?php echo $inputby =
'inputby'; //replace variable $inputby ?>">
<div class="form-group">
<label for="comment" class="control-label">Project Notes *</label>
<textarea class="form-control form-control-md" rows="3" cols="25"
name="comment" style="resize: none;" id="comment" placeholder="Type
your comment here...." required></textarea>
</div>
<input type="submit" class="btn btn-success" id="savenotes"
name="submit" value="Submit Comment" />
</form>
</div>
<!-- I can't find where your Comments are appended
to, so I placed them here using the
class name 'comment-block' as you used in your script -->
<div class="row justify-content-center">
<div class="comment-block"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-
default">Close</button>
</div>
</div>
</div>
</div>
Then this is your myjobspage.php where you will include the modal.php
<?php
include 'modal.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Myjobspage</title>
<link rel="stylesheet"
href="path/to/bootstrap4.0.0/dist/css/bootstrap.min.css">
<script src="path/to/Jquery_3.2.1/jquery-3.2.1.js"></script>
<script src="path/to/bootstrap-
4.0.0/assets/js/vendor/popper.min.js">
</script>
<script src="path/to/bootstrap-4.0.0/dist/js/bootstrap.min.js">
</script>
</head>
<body>
<!-- Some Code Here-->
<!-- Button to Launch Modal. Replace appropriately-->
<button type="button" class="btn btn-primary" data-toggle="modal"
data-target="#projnotes">
Launch Comments Modal
</button>
<!-- some other code -->
<!-- script to trigger your modal.php -->
<script src="modalScript.js"></script>
<script src="path/to/bootstrap-4.0.0/js/dist/util.js"></script>
<script src="path/to/bootstrap-4.0.0/js/dist/modal.js"></script>
</body>
</html>
This is the script modalScript.js that will make the request to projectnoteuploads.php via the ajax method.
$(document).ready(function(){
$('form').on('submit', function(e) {
e.preventDefault();
$.ajax({
url: 'projectnoteuploads.php',
type: 'POST',
cache: false,
data: $('form').serialize(),
success: function(data){
console.log(data);
//This I guess was where the error was in the previous code.
$('.comment-block').append(data).hide().fadeIn(800);
$('textarea').val(''); //This will wipe out the textarea after
//comment input
},
error: function(e){
alert(e);
}
});
});
});
Please take note, the codes have all being modified from the question, I tried it and it works.