I need to pass id
of a modal to my controller.php
. In the modal, clicking on the "delete" button I'm trying to pass via POST
id
of the client, but the controller does not receive anything.
Here I get the data that is in the database:
foreach($dados as $row){
$idCliente = $row['idClienteFisico'];
$nomeCliente = $row['nomeCliente'];
$rgCliente = $row['rgCliente'];
$cpfCliente = $row['cpfCliente'];
}
Here is the button that activates modal and passes to jQuery the id
and name by data-id
and data-nome
.
<button type="button" data-id="<?php echo $idCliente; ?>" data-nome="<?php echo $nomeCliente; ?>" data-remote="false" data-toggle="modal" data-target="#exampleModal" class="btn btn-danger"><em class="fa fa-trash"></em></button>
Here is my Bootstrap Modal where I get the id
and the client name
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<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="exampleModalLabel">Excluir Cliente</h4>
</div>
<div class="modal-body">
<form action="../Controller/cadastro.php" method="post">
<div class="form-group">
<h3>Deseja excluir</h3>
<label for="recipient-name" class="control-label">ID:</label>
<input type="text" class="form-control hidden" id="recipient-name" name="id">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger" value="btnDelete" name="btnDelete">Excluir</button>
</div>
</form>
</div>
</div>
</div>
</div>
This is where I open the modal and where I pass the id and the name of the client by the "date-id" and "date-name" of my button.
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var id = button.data('id')
var nome = button.data('nome')
var modal = $(this)
modal.find('.modal-body input').val(id)
modal.find('.modal-body h3').text('Deseja excluir o usuario ' +nome+ '?')
})
My controller.php looks like this:
if(isset($_POST['btnDelete'])){
$dao = new funcionarioDAO();
$dao->Deletar($_GET['id']);
}
The way it's there I'm getting id
and the name in the modal. But I do not know how to send id
via POST
to my controller.php
who will receive id
and delete the Client.
Any Suggestions?