From cceab89523598926a711da2b0943b698ec7aa461 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Fri, 24 May 2024 13:46:06 +0200 Subject: [PATCH] HW start --- base/errors.php | 4 -- base/headers.php | 2 +- base/settings.php | 7 +++ homework/colourSelector/index.php | 46 ++++++++++++++++++++ homework/colourSelector/js/formValidation.js | 33 ++++++++++++++ tasks/calc/index.php | 4 +- tasks/counter/data/counter.txt | 1 + tasks/counter/index.php | 36 +++++++++++++++ tasks/guestBook/actions/comment.php | 2 +- tasks/guestBook/data/data.json | 2 +- tasks/guestBook/index.php | 4 +- tasks/random/arrays.php | 2 +- test/action.php | 2 +- test/index.php | 4 +- 14 files changed, 134 insertions(+), 15 deletions(-) delete mode 100644 base/errors.php create mode 100644 base/settings.php create mode 100644 homework/colourSelector/index.php create mode 100644 homework/colourSelector/js/formValidation.js create mode 100644 tasks/counter/data/counter.txt create mode 100644 tasks/counter/index.php diff --git a/base/errors.php b/base/errors.php deleted file mode 100644 index 32d7093..0000000 --- a/base/errors.php +++ /dev/null @@ -1,4 +0,0 @@ - + + + + + + Colour Selector + + + + + + + + +
+ + +
+
+
+ + +
+ Please enter valid hex colour code +
+
+ +
+ + + \ No newline at end of file diff --git a/homework/colourSelector/js/formValidation.js b/homework/colourSelector/js/formValidation.js new file mode 100644 index 0000000..77f2903 --- /dev/null +++ b/homework/colourSelector/js/formValidation.js @@ -0,0 +1,33 @@ +"use strict"; + +document.addEventListener("DOMContentLoaded", () => { + const _switch = document.getElementById("clientSideValidate"); + _switch.addEventListener("change", () => + _switch.checked ? addValidation() : removeValidation() + ); +}); + +const handler = (event) => { + if (!event.target.checkValidity()) { + event.preventDefault(); + event.stopPropagation(); + } + + event.target.classList.add("was-validated"); +}; + +const addValidation = () => { + const forms = document.querySelectorAll(".needs-validation"); + + Array.from(forms).forEach((form) => { + form.addEventListener("submit", handler, false); + }); +}; + +const removeValidation = () => { + const forms = document.querySelectorAll(".needs-validation"); + + Array.from(forms).forEach((form) => { + form.removeEventListener("submit", handler, false); + }); +}; diff --git a/tasks/calc/index.php b/tasks/calc/index.php index 17dcaa7..fe42874 100644 --- a/tasks/calc/index.php +++ b/tasks/calc/index.php @@ -1,5 +1,5 @@ - + @@ -11,7 +11,7 @@ + + + + + + Counter + + + + time() + 60 * 60 * 24, "samesite" => "strict", "secure" => true, "httponly" => true]); + } + } + flock($fh, LOCK_UN); + fclose($fh); + + Headers::html(); + ?> +

Visitor count:

+ + + \ No newline at end of file diff --git a/tasks/guestBook/actions/comment.php b/tasks/guestBook/actions/comment.php index e0fb52b..d91f03f 100644 --- a/tasks/guestBook/actions/comment.php +++ b/tasks/guestBook/actions/comment.php @@ -1,5 +1,5 @@ "},{"time":1716546110,"title":"JS Inject","name":"Kilian","comment":"