This commit is contained in:
Yanislav Igonin 2022-04-13 09:38:15 +03:00
parent ce98428cbe
commit aba8e48a0e
4 changed files with 21 additions and 9 deletions

View File

@ -262,6 +262,10 @@ func UpdateThread(c *fiber.Ctx) error {
CaptchaID: captchaID,
IsCaptchaActive: config.App.IsCaptchaActive,
Errors: *validationErrors,
Inputs: repositories.Inputs{
Text: text,
Files: filesInRequest,
},
},
}

View File

@ -1,6 +1,9 @@
package repositories
import "time"
import (
"mime/multipart"
"time"
)
// DB Structs
// DB Structs
@ -40,18 +43,23 @@ type File struct {
// HTML Templates Structs
// post-form.html
type Inputs struct {
type Errors struct {
Title string
Text string
Files string
}
type Inputs struct {
Title string
Text string
Files []*multipart.FileHeader
}
// post-form.html
type HtmlFormData struct {
FirstPostID int
CaptchaID string
IsCaptchaActive bool
Errors Inputs
Errors
Inputs
}

View File

@ -10,13 +10,13 @@
{{ if eq .FirstPostID 0 }}
<label class="form-error-label" for="title">{{ .Errors.Title }}</label>
<input class="form-control" id="postTitle" placeholder="Title" name="title">
<input class="form-control" id="postTitle" placeholder="Title" name="title" value={{ .Inputs.Title }}>
{{ end }}
<label class="form-error-label" for="text">{{ .Errors.Text }}</label>
<textarea class="form-control" id="postText" rows="5" placeholder="Text" name="text"></textarea>
<textarea class="form-control" id="postText" rows="5" placeholder="Text" name="text">{{ .Inputs.Text }}</textarea>
<label class="form-error-label" for="files">{{ .Errors.Files }}</label>
<input class="form-control" type="file" id="postFiles" multiple name="files">
<input class="form-control" type="file" id="postFiles" multiple name="files" accept="image/jpeg, image/png"}>
{{ if .IsCaptchaActive }}
{{ template "captcha" .CaptchaID }}

View File

@ -101,8 +101,8 @@ func ValidatePost(title, text string, files []*multipart.FileHeader) string {
return ""
}
func ValidatePost2(title, text string, files []*multipart.FileHeader) *repositories.Inputs {
validationErrors := new(repositories.Inputs)
func ValidatePost2(title, text string, files []*multipart.FileHeader) *repositories.Errors {
validationErrors := repositories.Errors{}
hasErrors := false
if text == "" && len(files) == 0 {
@ -139,7 +139,7 @@ func ValidatePost2(title, text string, files []*multipart.FileHeader) *repositor
}
if hasErrors {
return validationErrors
return &validationErrors
}
return nil