I'm developing a client signup screen with PHP OO but due to my inexperience I'm 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 the registered clients: Code:
<?phpforeach($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: LookupClients () returns an Array of Client objects where the index is the client ID.
Jquery code of Bootstrap modal:
<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 to open Modal with all the data of the respective client 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 did not understand how to use it for that purpose.
Could you help me and if possible, how do I do this?