support radio buttons

This commit is contained in:
2020-08-18 13:04:26 +02:00
parent 339be5e755
commit c4fe2bf6d2
6 changed files with 150 additions and 13 deletions

View File

@@ -109,12 +109,12 @@ func (wc *WebController) adminAbuseForm(td *TemplateData, r *http.Request) (f Fo
Name: "type",
Label: "Type",
DefaultValue: "unknown",
Description: "Can be 'unknown', 'copyright', 'terrorism' or 'child_abuse'",
Type: FieldTypeText,
Type: FieldTypeRadio,
RadioValues: []string{"unknown", "copyright", "terrorism", "child_abuse"},
}, {
Name: "reporter",
Label: "Reporter",
DefaultValue: "pixeldrain",
DefaultValue: "Anonymous tip",
Type: FieldTypeText,
},
},

View File

@@ -60,6 +60,9 @@ type Field struct {
// Only used when Type == FieldTypeCaptcha
CaptchaSiteKey string
// Only used when Type == FieldTypeRadio
RadioValues []string
}
// ExtraActions contains extra actions to performs when rendering the form
@@ -84,6 +87,7 @@ const (
FieldTypeNumber FieldType = "number"
FieldTypeUsername FieldType = "username"
FieldTypeEmail FieldType = "email"
FieldTypeRadio FieldType = "radio"
FieldTypeCurrentPassword FieldType = "current-password"
FieldTypeNewPassword FieldType = "new-password"
FieldTypeCaptcha FieldType = "captcha"
@@ -103,7 +107,7 @@ func (f *Form) ReadInput(r *http.Request) (success bool) {
// Remove carriage returns
field.EnteredValue = strings.ReplaceAll(r.FormValue(field.Name), "\r", "")
if field.DefaultValue == "" {
if field.EnteredValue != "" {
field.DefaultValue = field.EnteredValue
}