Skip to content

Commit cd425fa

Browse files
FlyingCowMasterJoseph Rosso
andauthored
Limited poll title character length to 250 (#115)
* Limited poll title character length to 250 * Added backend validation for poll title length --------- Co-authored-by: Joseph Rosso <jdr1652@rit.edu>
1 parent 76edb9b commit cd425fa

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ func CreatePoll(c *gin.Context) {
139139
return
140140
}
141141

142+
// If title length exceeds 250 characters, return a bad request
143+
if len(c.PostForm("title")) > 250 {
144+
c.JSON(http.StatusBadRequest, gin.H{"error": "title length exceeds limit of 250 characters"})
145+
return
146+
}
147+
142148
quorumType := c.PostForm("quorumType")
143149

144150
quorum, err := strconv.ParseFloat(quorumType, 64)

templates/create.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
type="text"
1010
class="form-control"
1111
name="title"
12-
placeholder="My Poll"
12+
placeholder="My Poll (max 250 characters)"
13+
maxlength="250"
1314
required
1415
>
1516
</div>

0 commit comments

Comments
 (0)