0
I need to take the dynamically generated sequential Ids from the PHP loop to open a Modal without bootstrap.
I have tried several things I saw on the internet, I come here to try something so that my modal open and present the user data of that ID.
Note: I don’t want to use boostrap for this.
It is a CRUD where the delete button opens a modal to confirm user deletion.
From now on I thank you all!
<?php foreach ($model->all() as $key => $value) : ?>
<div class="linhas">
<tr>
<th><?php echo $value['id']; ?></th>
<td><?php echo $value['firstname'] . ' ' . $value['lastname']; ?></td>
<td><?php echo $value['email']; ?></td>
<td><?php echo $value['created_at']; ?></td>
<div class="menu">
<td>
<!-- Botão editar -->
<a href="/useredit/<?php echo $value['id']; ?>" id="btn_edit<?php echo $value['id']; ?>" class="btn_edit">Editar</a>
</td>
<td>
<div class="btndel" id="btndel">
<!-- Botão deletar -->
<a href="" class="btn_del" id="btn_del<?php echo $value['id']; ?>">Apagar</a>
</div>
</td>
</div>
</tr>
<div class="mod-container" id="mod_container">
<div class="mod">
<h1>Modais são legais</h1>
<p>um monte de texto aqui</p>
<button class="" id="close">Fechar</button>
</div>
</div>
</div>
<?php endforeach; ?>
<script type="text/javascript">
const mod_container = document.getElementById('mod_container');
const close = document.getElementById('close');
const btn_del = document.getElementById('btn_del');
btn_del.addEventListener('click', () => {
mod_container.classList.add('show');
});
close.addEventListener('click', () => {
mod_container.classList.remove('show');
});
</script>
<style type="text/css">
.mod-container {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
opacity: 0;
pointer-events: none;
top: 0;
left: 0;
height: 100vh;
width: 100vh;
transition: opacity 0.3s ease;
}
.mod-container.show {
pointer-events: auto;
opacity: 1;
}
.mod {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
padding: 30px 60px;
width: 600px;
max-width: 100%;
text-align: center;
}
.mod h1 {
margin: 0;
}
.mod p {
font-size: 14px;
opacity: 0.7;
}
</style>