Landing page – What about comments?
So last time a basic landing page was created, but (besides the styling) there was something missing.
The comments
Available comments wouldn’t be shown AND there was no possibility of commenting on articles, this is about to be changed.
As there already is the getPosts-function this should be today’s starting point, so let’s get us another function that fetches the comments.
The new function is named getCommentsForArticle and takes exactly one parameter which is the articleId. All comments for the given articleId are fetched by simply joining the comments- and articlecomments-tables together. The result of this select will be stored in the article-array as comments.
Next the landing page must be enhanced to display the comments (if there are any).
So the foreach-loop in the main-section will receive some work…
First of all the number of comments is counted and a new div is added to the article-section(s).
If there are comments the count is displayed here, if there are none there should be a link that allows the users to leave a comment.
Not much of a fuss so far, let’s go on by really displaying the existing comments.
So I’m adding another foreach-loop in the else-branch of the comment-section which will simply loop over all available comments and display them.
No matter if there are comments or not, the Leave a comment-area should be displayed, so this (or at least a dummy) will be added next.
If someone comments at least a comment and a nickname should be given, so on the creation page these two values will be checked first and the user will be prompted an error message if those are not set, else the comment will be added to the database and if the add is successful the new comment is linked to the article.
Now there is one thing left to add, which is a captcha.
As I do want to use as little javascript as possible the widely used reCaptcha is no alternative which means I might have to write my own…
The captcha is a generated white png with a random string with length seven put into the image. The random string is also saved in a session variable so that we can check for equality.
So long
Sven