diff --git a/tasks/guestBook/comment.php b/tasks/guestBook/comment.php new file mode 100644 index 0000000..53360bc --- /dev/null +++ b/tasks/guestBook/comment.php @@ -0,0 +1,45 @@ + 0) { + Headers::redirect("."); + return; +} + +$string = file_get_contents("data.json") ?? "[]"; +$json = json_decode($string); + +array_push($json, ["time" => $time, "title" => $title, "name" => $name, "comment" => $comment]); + +file_put_contents("data.json", json_encode($json)); + +Headers::redirect("."); diff --git a/tasks/guestBook/data.json b/tasks/guestBook/data.json new file mode 100644 index 0000000..74f1b0f --- /dev/null +++ b/tasks/guestBook/data.json @@ -0,0 +1 @@ +[{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715337098,"title":"The first","name":"Kilian","comment":"The first comment on here."},{"time":1715338181,"title":"","name":"asd","comment":"sad"},{"time":1715338381,"title":"sdf","name":"dsaf","comment":"dsg"},{"time":1715339761,"title":"Witzige Aufgabe","name":"Kilian","comment":"nun ja, also das funktioniert ja schon recht gut gell."}] \ No newline at end of file diff --git a/tasks/guestBook/formValidation.js b/tasks/guestBook/formValidation.js new file mode 100644 index 0000000..95c9195 --- /dev/null +++ b/tasks/guestBook/formValidation.js @@ -0,0 +1,22 @@ +"use strict"; + +document.addEventListener("DOMContentLoaded", () => { + 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); + }); + }; + + addValidation(); +}); diff --git a/tasks/guestBook/index.php b/tasks/guestBook/index.php new file mode 100644 index 0000000..ebde3f3 --- /dev/null +++ b/tasks/guestBook/index.php @@ -0,0 +1,146 @@ + + + +
+ + + += $comment->comment ?>
+