diff --git a/actions/get.php b/actions/get.php index 4d8a893a666eed3314007778dc4d9516140518da..ece647f9bcaf0c0d13ba5cd52b6002bfd83ddeae 100644 --- a/actions/get.php +++ b/actions/get.php @@ -1,7 +1,9 @@ -<?php require_once(__DIR__.'/../static/php/head.php'); ?> -<?php echo htmlspecialchars($_GET['name']).' | Score : '; ?> -<?php $score = $ddb->query(' +<?php +require_once(__DIR__.'/../config/config.php'); + +$score = $ddb->query(' SELECT score FROM users WHERE name = \''.$_GET['name'].'\' ')->fetch(); - echo $score[0] + +echo htmlspecialchars($_GET['name']).' | Score : '.$score[0] ?> diff --git a/pages/pageForm.php b/pages/pageForm.php index 8162e3461e49be6c6d94d3de3db6383a17d5a6b6..ac91f18b6064f2ccdc17dd1c8f11554f54f18242 100644 --- a/pages/pageForm.php +++ b/pages/pageForm.php @@ -1,6 +1,7 @@ <?php require_once(__DIR__.'/../static/php/head.php'); ?> <body> <?php require_once(APP_ROOT.'/static/php/navbar.php'); ?> + <!-- Formulaires classiques --> <form action="/actions/post.php" method="post"> <label for="name"><?php echo $trad['form_name'][$lang]; ?></label> <input name="name" id="name" type="text"> @@ -17,4 +18,17 @@ <button type="submit"><?php echo $trad['search'][$lang]; ?></button> </form> + <br> + <!-- Formulaire AJAX --> + <script src="/static/js/ajax.js"></script> + <div> + <form onsubmit="submitFormGetAjax(this)"> + <label for="name"><?php echo $trad['form_name'][$lang]; ?></label> + <input name="name" id="name" type="text"> + + <button type="submit"><?php echo $trad['search'][$lang]; ?></button> + </form> + <br> + <label id="result"></label> + </div> </body> diff --git a/static/js/ajax.js b/static/js/ajax.js new file mode 100644 index 0000000000000000000000000000000000000000..89cc26aadc3ea80c1a708a2350fb23161ceae739 --- /dev/null +++ b/static/js/ajax.js @@ -0,0 +1,15 @@ +function submitFormGetAjax(form) { + event.preventDefault(); + + var request = new XMLHttpRequest(); + request.onreadystatechange = function() { + // uniquement en cas de requête envoyée et réussie + if (this.readyState == 4 && this.status == 200) + document.getElementById("result").innerHTML = request.responseText; + }; + + let name = encodeURIComponent(form.name.value.trim()); + + request.open("GET", "/actions/get.php?name=" + name, true); + request.send(); +} diff --git a/static/js/blogfolio.js b/static/js/blogfolio.js deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000