# HG changeset patch # User Yader Velasquez # Date 1671471519 21600 # Mon Dec 19 11:38:39 2022 -0600 # Node ID 99d5f5013d9935e2b5abebeabb8c701f793828b3 # Parent b84777c9a94db0c01550a877de42773e7fe4e159 Move FieldName to struct diff --git a/formguard.go b/formguard.go --- a/formguard.go +++ b/formguard.go @@ -12,13 +12,18 @@ type Form struct { AntiSpamField int MinValue int + FieldName string } // Validate ... -func (f *Form) Validate(c echo.Context, fieldName string) error { +func (f *Form) Validate(c echo.Context) error { + if f.FieldName == "" { + f.FieldName = "antispam" + } + errs := echo.FormFieldBinder(c). FailFast(false). - Int(fieldName, &f.AntiSpamField). + Int(f.FieldName, &f.AntiSpamField). BindErrors() if errs != nil { return validate.GetInputErrors(errs)