From fbac380ec400bb823c6835b4a197829274a69fe6 Mon Sep 17 00:00:00 2001 From: Jonas Leder <git@jonasled.de> Date: Mon, 12 Apr 2021 20:33:24 +0200 Subject: [PATCH] add custome element for new comment --- js/customElements/newComment.js | 31 +++++++++++++++++++++++++++++++ js/script.js | 3 ++- public/API/lib/mysql.php | 1 - public/internal/comments.php | 22 ++-------------------- 4 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 js/customElements/newComment.js diff --git a/js/customElements/newComment.js b/js/customElements/newComment.js new file mode 100644 index 0000000..6c113fe --- /dev/null +++ b/js/customElements/newComment.js @@ -0,0 +1,31 @@ +class newComment extends HTMLElement { + constructor() { + super(); + this.setupForm(); + } + + async setupForm(){ + let sitekey = await (await fetch("/API/config.php?name=sitekey")).text(); + + this.innerHTML = ` + <form action="/newComment.php" method="post"> + <label for="name">Name:</label><br> + <input type="text" id="name" name="name"><br><br> + + <label for="email">E-Mail: (wird nicht veröffentlicht)</label><br> + <input type="text" id="email" name="email"><br><br> + + <label for="comment">Kommentar:</label><br> + <textarea name="comment" id="comment"></textarea><br><br> + + <div class="h-captcha" data-theme="dark" data-sitekey="${sitekey}"></div><br> + + <input type="submit" value="Kommentar veröffentlichen"><br> + <p>Mit dem Klick auf den obigen Button erklären sie sich mit der <a href="/datenschutzerklaerung.html">Datenschutzerklärung</a> einverstanden.</p> + </form> + `; + + } +} + +customElements.define("jl-new_comment", newComment); \ No newline at end of file diff --git a/js/script.js b/js/script.js index 3989a8c..1057467 100644 --- a/js/script.js +++ b/js/script.js @@ -9,4 +9,5 @@ require("./customElements/cookie"); require("./customElements/svgLoader"); require("./customElements/blogFooter"); require("./customElements/blogIndex"); -require("./customElements/commentsDisplay"); \ No newline at end of file +require("./customElements/commentsDisplay"); +require("./customElements/newComment"); \ No newline at end of file diff --git a/public/API/lib/mysql.php b/public/API/lib/mysql.php index 5c1d19b..7c09f2e 100644 --- a/public/API/lib/mysql.php +++ b/public/API/lib/mysql.php @@ -1,5 +1,4 @@ <?php -include "config.php"; $conn = new mysqli($mysqlServer, $mysqlUser, $mysqlPassword, $mysqlDatabase); // Check connection diff --git a/public/internal/comments.php b/public/internal/comments.php index c62d382..f0bcea7 100644 --- a/public/internal/comments.php +++ b/public/internal/comments.php @@ -2,27 +2,9 @@ function getComments($article){ echo(<<<EOF + <script src='https://www.hCaptcha.com/1/api.js' async defer></script> <h2>Kommentare:</h2> <jl-comments_display></jl-comments_display> -<script src='https://www.hCaptcha.com/1/api.js' async defer></script> -<div id="newComment"> - <form action="/newComment.php" method="post"> - <label for="name">Name:</label><br> - <input type="text" id="name" name="name"><br><br> - - <label for="email">E-Mail: (wird nicht veröffentlicht)</label><br> - <input type="text" id="email" name="email"><br><br> - - <label for="comment">Kommentar:</label><br> - <textarea name="comment" id="comment"></textarea><br><br> - - <div class="h-captcha" data-theme="dark" data-sitekey="$sitekey"></div><br> - - <input type="submit" value="Kommentar veröffentlichen"><br> - <p>Mit dem klick auf den obigen Button erklären sie sich mit der <a href="/datenschutzerklaerung.html">Datenschutzerklärung</a> einverstanden.</p> - </form> -</div> - - + <jl-new_comment id="newComment"></jl-new_comment> EOF); } \ No newline at end of file -- GitLab