A friend highlighted to me that my guestbook didnāt have any moderation, I get emails every time someone submits a comment, but depending on my access to a device, a potentially harmful comment could be left exposed to others until I am able to delete it.
My guestbook is based on Virtual Observerās comment widget, which uses a Google sheet as a database, itās super clever and up until now Iāve only made a couple of minor modifications to fit my website. This modification is more functional and could benefit others significantly, so here is my walkthrough on how to do it yourself. To get to this point, you should already have followed the rest of Virtual Observerās instructions on how to install the comment widget.
How to do it
- Go to the form that you set up for your comment widget and add a new short-answer text question at the bottom.
- Name this question āModeratedā. Donāt forget the capitalise the first letter as the code is case sensitive.
- Add a layer of security, press the three dots in the bottom left corner of the new āModeratedā question, select āResponse Validationā and add the settings: āTextā āContainsā āfalseā *
- From your Google form, press the three dots in the top left corner and then āGet pre-filled linkā. This will open a new tab with your form, as if you were answering it. Fill in every field with the same name as its respective title and then press āGet linkā.
- Paste the link into a text editor and scoop out the number after the final
entry.which should have the value that you filled in: āModeratedā. It will look something like this:
&entry.123456789=Moderated
- In the file that you originally downloaded from Virtual Observer, find the variable
const s_textId = '123456789';and paste the following on the line below, replacing the number with the number you scooped out in step 4.
const s_moderatedId = '123456789'; // The Moderated field ID
- Now we need to add a hidden input field that automatically sets this value to false in your Google sheet. Find the textarea with
id="entry.${s_textId}"and below this line, add the following.
<input name="entry.${s_moderatedId}" id="entry.${s_moderatedId}" type="hidden" readonly value="false">
- Next, find
name.className = 'c-name';and below this line add the following:
if(data.Moderated == false) {
name.innerText = 'Guest'; // Change 'Guest' to whatever you want
}
- Next, find
site.className = 'c-site';and below this line add the following:
if(data.Moderated == false) {
site.innerText = '';
}
- Next, find
text.className = 'c-text';and below this line add the following:
if(data.Moderated == false) {
text.innerText = 'This comment is awaiting moderation'; // Change this value to whatever you want
}
And youāre done! If you already have comments stored in your Google sheet, change the āModeratedā value to TRUE for them to show.
When a new comment is submitted the āModeratedā value will be FALSE. Once youāre happy for the comment to be displayed on your website, go into your Google sheet and change it to TRUE.
If you implement this, leave me a comment in my guestbook to let me know!
Iād love to know if this is useful to you.