The Problem:
I want to get the reservationid out of the clicked td into my Bootstrap modal.
JS Code:
$('#reservationtable tbody td').on('click', function () {
if($(this).hasClass("reserved") || $(this).hasClass("reserved-right")){
var reservationid = $(this).attr('id');
$.ajax({
cache: false,
type: 'POST',
url: 'abfragereservierung.php',
data: 'reservationid='+reservationid,
success: function(data)
{
$('#abfrageresrvierung').show();
}
});
}
});
HTML Code:
<td class="reserved" data-id="'. $counter['1']->reservationid .'">
<td class="reserved" data-id="'. $counter['2']->reservationid .'">
<td class="reserved" data-id="'. $counter['3']->reservationid .'">
Inside of the $counter variable is for each key (1,2,3) a Object of the type Reservation
Bootstrap Modal:
<?php
session_start();
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/User.php");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/ReservierungsController.php");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/UserController.php");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/Reservierung.php");
$resController = new ReservierungsController();
//PLACE WHERE I WANT TO GET THE RESERVATIONID
?>
<div class="modal fade" id="abfragereservierung" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
.....
UPDATE:
Now i see a POST request with the correct reservationid in it. But i can't use it via $_POST['reservationid']
MODAL:
<?php
session_start();
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/User.php");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/ReservierungsController.php");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/UserController.php");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/Reservierung.php");
$userController = new UserController();
$resController = new ReservierungsController();
if($_POST['reservationid'] != ""){
$reservierung = $resController->getReservierungFromId($_POST['reservationid']);
}
?>
<form method="post">
<div class="modal fade" id="abfragereservierung" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Reservierung Nr. <?php echo $reservierung->reservationid ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h6>Daten</h6>
<div id="reservationdata">
<table class="table table-hover">
<tbody>
<tr>
<th>Name</th>
<td><p><?php echo $userController->getUserFromId($_POST['reservationid'])->nachname ?></p></td>
</tr>
<tr>
<th>Platz</th>
<td><p><?php echo $reservierung->tenniscourts_tenniscourtid ?></p></td>
</tr>
<tr>
<th>Datum</th>
<td><p><?php echo $reservierung->reservierung_am ?></p></td>
</tr>
<tr>
<th>Uhrzeit von</th>
<td><p><?php echo $reservierung->reservierungsanfang ?></p></td>
</tr>
<tr>
<th>Uhrzeit bis</th>
<td><p><?php echo $reservierung->reservierungsende ?></p></td>
</tr>
<tr>
<th>Bemerkung</th>
<td><p><?php echo $reservierung->bemerkung ?></p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Abbrechen</button>
<button class="btn btn-warning" type="submit" name="submit" id="submit" value="submit">Reservierung stornieren</button>
</div>
</div>
</div>
</div>
</form>