From 0410065d5d61b369d60142217f15615744f8d9b5 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 26 Aug 2022 20:07:55 -0700 Subject: [PATCH] Don't allow posting an empty comment --- pkg/controller/comment/post_comment.go | 7 +++++++ web/templates/photo/permalink.html | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/controller/comment/post_comment.go b/pkg/controller/comment/post_comment.go index fd7d4c5..209f16e 100644 --- a/pkg/controller/comment/post_comment.go +++ b/pkg/controller/comment/post_comment.go @@ -131,6 +131,13 @@ func PostComment() http.HandlerFunc { if r.Method == http.MethodPost { // Default intent is preview unless told to submit. if intent == "submit" { + // A message is required. + if message == "" { + session.FlashError(w, r, "A message is required for your comment.") + templates.Redirect(w, fromURL) + return + } + // Are we modifying an existing comment? if comment != nil { comment.Message = message diff --git a/web/templates/photo/permalink.html b/web/templates/photo/permalink.html index a1aa4d8..3f8cb3a 100644 --- a/web/templates/photo/permalink.html +++ b/web/templates/photo/permalink.html @@ -161,7 +161,8 @@ + placeholder="Add your comment" + required>

Markdown formatting supported.