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, CaptchaID: captchaID,
IsCaptchaActive: config.App.IsCaptchaActive, IsCaptchaActive: config.App.IsCaptchaActive,
Errors: *validationErrors, Errors: *validationErrors,
Inputs: repositories.Inputs{
Text: text,
Files: filesInRequest,
},
}, },
} }

View File

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

View File

@ -10,13 +10,13 @@
{{ if eq .FirstPostID 0 }} {{ if eq .FirstPostID 0 }}
<label class="form-error-label" for="title">{{ .Errors.Title }}</label> <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 }} {{ end }}
<label class="form-error-label" for="text">{{ .Errors.Text }}</label> <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> <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 }} {{ if .IsCaptchaActive }}
{{ template "captcha" .CaptchaID }} {{ template "captcha" .CaptchaID }}

View File

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