Compare commits

...

3 Commits

Author SHA1 Message Date
a20226595b New folder structure 2024-05-24 11:17:13 +02:00
2c947a0dfa Textarea Progress 2024-05-24 10:59:55 +02:00
2680b8841e Fix Validation 2024-05-24 10:58:14 +02:00
12 changed files with 62 additions and 103 deletions

View File

@ -1,4 +1,7 @@
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Kilian Kurt Hofmann" />
<meta name="copyright" content="Kilian Kurt Hofmann" />
<meta name="robots" content="noindex" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>

View File

@ -2,14 +2,10 @@
<html lang="de">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include_once "../../base/meta.php" ?>
<title>Calculator</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="formValidation.js"></script>
</head>

View File

@ -1,6 +1,6 @@
<?php
include_once "../../base/errors.php";
include_once "../../base/headers.php";
include_once "../../../base/errors.php";
include_once "../../../base/headers.php";
session_start();
$_SESSION["error"] = [];
@ -35,11 +35,11 @@ if (count($_SESSION["error"]) > 0) {
return;
}
$string = file_get_contents("data.json") ?? "[]";
$string = file_get_contents("../data/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));
file_put_contents("../data/data.json", json_encode($json));
Headers::redirect(".");
Headers::redirect("../");

View File

@ -1,7 +1,7 @@
<div class="col">
<div class="card h-100">
<div class="card-header">
<h5 class="card-title"><?= $comment->title ?></h5>
<h5 class="card-title lh-base text-truncate"><?= $comment->title ?></h5>
<h6 class="card-subtitle mb-2 text-muted"><?= $comment->name ?></h6>
</div>
<div class="card-body">

View File

@ -1,31 +1,4 @@
<style>
#comment {
resize: none;
overflow: hidden;
}
#comment-count {
right: 3px;
bottom: 0;
}
@supports selector(:has(html)) {
.was-validated .position-relative:has(:invalid)~.invalid-feedback {
display: block;
}
.was-validated :invalid~.invalid-feedback {
display: none !important;
}
}
@supports not selector(:has(html)) {
.was-validated :invalid~#comment-count {
display: none;
}
}
</style>
<form action="comment.php" method="post" class="needs-validation row m-0" novalidate>
<form action="./actions/comment.php" method="post" class="needs-validation row m-0" novalidate>
<div class="col">
<h4 class="mb-3">Leave a Comment!</h4>
<div class="mb-3">
@ -40,20 +13,15 @@
Please enter a name.
</div>
</div>
<div class="mb-3">
<div class="position-relative">
<textarea class="form-control" id="comment" name="comment" maxlength="250" required placeholder="Comment here"></textarea>
<div class="invalid-feedback">
Please enter text.
</div>
<small class="text-muted position-absolute" id="comment-count">
0/250
</small>
</div>
<div class="mb-1">
<textarea class="form-control" id="comment" name="comment" maxlength="250" required placeholder="Comment here"></textarea>
<div class="invalid-feedback">
Please enter text.
</div>
</div>
<button class="btn btn-primary mb-3">Comment</button>
<div class="progress mb-3">
<div class="progress-bar" id="comment-count" style="width: 0;"></div>
</div>
<button type="submit" class="btn btn-primary mb-3">Comment</button>
</div>
</form>

View File

@ -0,0 +1,2 @@
DENY FROM ALL
ALLOW FROM 127.0.0.1

View File

@ -1 +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."}]
[{"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":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."},{"time":1716539658,"title":"Progress Bar","name":"Kilian","comment":"Jetzt auch mit einem etwas geileren Progress Bar der einem die Character-Anzahl anzeigt.\r\nWesentlich geiler, wesentlich nicer, und Bootstraped"},{"time":1716541941,"title":"New layout","name":"Kilian","comment":"New folder structure"}]

View File

@ -6,8 +6,8 @@
<title>Guest Book</title>
<script src="formValidation.js"></script>
<script src="textarea.js"></script>
<script src="./js/formValidation.js"></script>
<script src="./js/textarea.js"></script>
</head>
<body>
@ -22,8 +22,8 @@
$errors = $_SESSION["error"] ?? [];
$_SESSION["error"] = [];
$string = file_get_contents("data.json") ?? "[]";
$json = json_decode($string);
$string = file_get_contents("./data/data.json") ?? "[]";
$json = array_reverse(json_decode($string));
if (isset($_GET["p"]) && !is_numeric($_GET["p"])) {
Headers::redirect(".");

View File

@ -0,0 +1,35 @@
"use strict";
document.addEventListener("DOMContentLoaded", () => {
const handlerCounter = (event) => {
const comment = event.target;
const length = comment.value.length;
const maxLength = comment.maxLength;
const counter = document.getElementById("comment-count");
if (length >= 50) {
counter.innerText = `${length}/${maxLength}`;
} else {
counter.innerText = "";
}
counter.style.width = `${(length / maxLength) * 100}%`;
if (length === maxLength) {
counter.classList.remove("bg-warning");
counter.classList.add("bg-danger");
} else if (length > maxLength - 50) {
counter.classList.remove("bg-danger");
counter.classList.add("bg-warning");
} else {
counter.classList.remove("bg-warning");
counter.classList.remove("bg-danger");
}
};
const addValidation = () => {
const comment = document.getElementById("comment");
comment.addEventListener("input", handlerCounter);
};
addValidation();
});

View File

@ -1,44 +0,0 @@
"use strict";
document.addEventListener("DOMContentLoaded", () => {
const handlerCounter = (event) => {
const comment = event.target;
const length = comment.value.length;
const maxLength = comment.maxLength;
const counter = document.getElementById("comment-count");
counter.innerText = `${length}/${maxLength}`;
if (length > maxLength - 50) {
counter.classList.remove("text-muted");
counter.classList.add("text-danger");
} else {
counter.classList.remove("text-danger");
counter.classList.add("text-muted");
}
};
const handlerSize = () => {
const scroll = window.scrollY;
const comment = document.getElementById("comment");
const counter = document.getElementById("comment-count");
const commentHeight = comment.clientHeight;
const counterHeight = counter.clientHeight;
if (commentHeight + 0.5 * counterHeight < comment.scrollHeight) {
comment.style.height = `${comment.scrollHeight + counterHeight}px`;
}
};
const addValidation = () => {
const comment = document.getElementById("comment");
const counter = document.getElementById("comment-count");
comment.style.height = `${comment.scrollHeight + counter.style.height}px`;
comment.addEventListener("input", handlerCounter);
comment.addEventListener("input", handlerSize);
window.addEventListener("resize", handlerSize);
};
addValidation();
});

View File

@ -2,10 +2,9 @@
<html lang="de">
<head>
<link href="index.css" rel="stylesheet" />
<?php include_once "../../base/meta.php" ?>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="index.css" rel="stylesheet" />
<title>Test</title>
</head>