Browse Source

Add simple url validation

master
Stephanie Gredell 1 year ago
parent
commit
3e760d2848
  1. 5
      pages/goals.go

5
pages/goals.go

@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"log" "log"
"net/http" "net/http"
"net/url"
"sponsorahacker/db" "sponsorahacker/db"
"sponsorahacker/utils" "sponsorahacker/utils"
"strconv" "strconv"
@ -45,7 +46,9 @@ func CreateGoal(c *gin.Context) {
description := strings.TrimSpace(c.PostForm("item-description")) description := strings.TrimSpace(c.PostForm("item-description"))
learnMoreURL := strings.TrimSpace(c.PostForm("item-url")) learnMoreURL := strings.TrimSpace(c.PostForm("item-url"))
if name == "" && fundingAmountStr == "" && description == "" && learnMoreURL == "" { _, validateErr := url.Parse(learnMoreURL)
if name == "" && fundingAmountStr == "" && description == "" && learnMoreURL == "" && validateErr != nil {
fieldError := fmt.Errorf("missing a required field. Please check and make sure all fields are filled out") fieldError := fmt.Errorf("missing a required field. Please check and make sure all fields are filled out")
c.HTML(http.StatusOK, "goals.html", gin.H{ c.HTML(http.StatusOK, "goals.html", gin.H{
"title": "Sponsor A Hacker", "title": "Sponsor A Hacker",

Loading…
Cancel
Save