https://openclassrooms.com/forum/sujet/variable-php-vers-javascript-1
-
-
Save julp/9d68275e9db5bd42bb9451eb888d36f5 to your computer and use it in GitHub Desktop.
[OC] Variable php vers javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$nonce = base64_encode(random_bytes(20)); | |
header("Content-Security-Policy: script-src 'nonce-{$nonce}'"); | |
?> | |
<script nonce="<?= $nonce ?>"> | |
function popupsupprimer(id, description) { | |
console.log([id, description]); | |
} | |
var ready = (callback) => { | |
if (document.readyState != 'loading') callback(); | |
else document.addEventListener('DOMContentLoaded', callback); | |
} | |
ready( | |
() => { | |
document.querySelectorAll('img.image').forEach( | |
element => { | |
element.addEventListener( | |
'click', | |
(event) => { | |
popupsupprimer(event.target.dataset.id, event.target.dataset.description); | |
} | |
) | |
} | |
); | |
} | |
) | |
</script> | |
<?php | |
$db = new PDO(...); | |
$images = $db->query('SELECT * FROM images'); | |
foreach ($image as $images): | |
?> | |
<IMG | |
class=image | |
title="icone pour supprimer" | |
style="height: 30px; width: auto; " | |
src="images/Supprimer.png" | |
alt="icone pour supprimer" | |
data-id="<?= $image['id'] ?>" | |
data-description="<?= htmlspecialchars($image['description']) ?>" | |
/> | |
<?php endforeach ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment