0
I am developing a client registration screen with PHP OO but due to my inexperience I am finding it difficult to list client data within a Modal Bootstrap.
First, I have this list of Client Objects where I present only some basic data of registered customers: Code:
<?php
foreach ($cliente->buscarClientes() as $key => $value){
echo "<tr>
<td><input type='checkbox' value='$key'</td>
<td>".$value->getNome()."</td>
<td>".$value->getCpf()."</td>
<td>".$value->getEmail()."</td>
<td>".$value->getDataCadastro()."</td>
<td>
<a href='#' data-toggle='modal' data-target='#modalCliente' data-clientmodal='$key'><i class='fa fa-edit' title='Editar'> </i></a>
<a href='#'> <i class='fa fa-trash' title='Excluir'> </i> </a>
</td>
</tr>";
}
?>
Note: searchClients() returns an Array of Client objects where the index is the client ID.
Jquery code of the modal Bootstrap:
<script>
$(function () {
// Modal editar/inserir cliente
$('#modalCliente').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('clientmodal') // Extract info from data-* attributes
var modal = $(this)
if(recipient !== null){
modal.find('.modal-title').text('Editar Cliente (#' + recipient + ")")
modal.find('.modal-body input#modal-idml').val("example")
} else {
modal.find('.modal-title').text('Novo cliente')
}
})
});
</script>
I would like the user to press the pencil icon Modal open with all the data of the respective customer to be able to edit them, if possible reusing the object that is already created. I tried to use AJAX in some ways, but I didn’t understand how to use it for that purpose.
Could you help me and if possible exemplify how I do it?
Thanks for the reply, I understood the way you did and I managed to pass this to my code, it was great
– R. Zanel