In my view I have the link, the modal box, and script. I have my ID on my modal but i can't send it on my controller.
The link:
<a href="#myModal" data-toggle="modal" id="<?php echo $salle['id_salle'];?>" data-target="#edit-modal"><span class="glyphicon glyphicon-pencil"></span></a>
My modal:
<div id="edit-modal" class="modal fade" 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>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body edit-content"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
And my script:
$( document ).ready(function() {
$('#edit-modal').on('show.bs.modal', function(e) {
var $modal = $(this),
Id = e.relatedTarget.id;
$.ajax({
method: 'POST',
url: 'index.php?section=gestion-salles',
data: 'id_salle='+Id,
success: function(data) {
alert(data);
$modal.find('.edit-content').html(Id + '<?php echo $test; ?> ' + 'id= <?php echo $id; ?>');
}
});
})
});
In my controller I defined a variable, $test
, and I recovered it. But I defined my variable $_POST['id_salle'] but can't recover it. I would like to send it to the controller and then do the processing but I can't.
Thank you.
My controller:
include_once('modele/set_salles.php');
include_once('modele/get_salles.php');
include_once('controleur/modal.php');
if(isset($_POST['bouton']))
{
if($_POST['titre'] !='' && $_POST['description'] !='' && $_POST['adresse'] !='' && $_POST['cp'] !=''){
$tmp_name = $_FILES["photo"]["tmp_name"];
$name = $_FILES["photo"]["name"];
set_salles(addslashes($_POST['titre']), addslashes($_POST['description']), $name, $_POST['pays'], $_POST['ville'], addslashes($_POST['adresse']), $_POST['cp'], $_POST['capacite'], $_POST['categorie']);
$uploads_dir = 'img/';
move_uploaded_file($tmp_name, "$uploads_dir/$name");
} else {
$remplir = '<p style="color:red">merci de remplir tous les champs</p>';
}
}
$salles = get_salles();
foreach($salles as $cle => $salle)
{
$salles[$cle]['titre'] = htmlspecialchars($salle['titre']);
$salles[$cle]['description'] = nl2br(htmlspecialchars($salle['description']));
}
$id = $_POST['id_salle'];
$test = 'Hello';
// On affiche les page (vues)
include_once('vue/include/header.php');
include_once('vue/include/navbar.php');
include_once('vue/gestion-salles.php');
include_once('vue/include/footer.php');