FrankNatoli Posted February 6, 2023 Posted February 6, 2023 (edited) Below is the standard Squarespace HTML to post comments. Would like to insert JavaScript to search the comment text for forbidden words or phrases, e.g., spam URLs, and if found refuse to post the comment. How to do so? Thanks. <!--NEW COMMENT TOP--> <div class="new-comment-area top-level-comment-area edit-mode"> <div class="input"> <form action="https://www.manhattancontrarian.com/blog/2023-2-4-in-new-york-a-very-slow-political-awakening#" method="post" class="comment-form"> <textarea class="comment-input" name="comment" data-defaulttext="Leave a comment here." data-edited="false"></textarea> </form> </div> <div class="comment-btn-wrapper"> <span class="btn-text preview-comment top-level-preview-btn">Preview</span> <span class="comment-btn sqs-system-button sqs-editable-button-font sqs-editable-button-shape sqs-button-element--primary"> Post Comment… </span> </div> </div> Edited February 7, 2023 by FrankNatoli
FrankNatoli Posted February 7, 2023 Author Posted February 7, 2023 (edited) I've tweaked the above Squarespace HTML to include a new "Post" button and a JavaScript function to check a list of forbidden words or phrases, which in the actual implementation would include the spam URLs. Question now is what is the proper syntax to invoke the "Post Comment" button in the original Squarespace HTML inside my JavaScript? Thanks <!DOCTYPE html> <html> <div class="new-comment-area top-level-comment-area edit-mode"> <div class="input"> <form action="https://www.manhattancontrarian.com/blog/2023-2-4-in-new-york-a-very-slow-political-awakening#" method="post" class="comment-form"> <textarea class="comment-input" id="comment" name="comment" data-defaulttext="Leave a comment here." data-edited="false" rows="10" cols="80"></textarea> </form> </div> <div class="comment-btn-wrapper"> <span class="btn-text preview-comment top-level-preview-btn">Preview</span> <span class="comment-btn sqs-system-button sqs-editable-button-font sqs-editable-button-shape sqs-button-element--primary">Post Comment…</span> </div> <button onclick="CheckComment()">Post</button> </div> <script type="text/javascript"> var verbotenList = ["forbidden1", "forbidden2"]; function CheckComment() { var commentText = document.getElementById("comment").value; alert(commentText); var verbotenFound = 0; for (var i = 0; i < verbotenList.length; i++) { if (commentText.search(verbotenList[i]) >= 0) { verbotenFound++; } } alert("verbotenFound=" + verbotenFound); if (verbotenFound == 0) { alert("comment approved"); } else { alert("comment not approved"); } } </script> </body> </html> Edited February 7, 2023 by FrankNatoli
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment