github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume4/section2/gopherface/forms/myprofile.go (about) 1 package forms 2 3 import ( 4 "go.isomorphicgo.org/go/isokit" 5 ) 6 7 type MyProfileForm struct { 8 isokit.BasicForm 9 } 10 11 func NewMyProfileForm(formParams *isokit.FormParams) *MyProfileForm { 12 prefillFields := []string{"firstName", "lastName", "email", "messageBody"} 13 fields := make(map[string]string) 14 errors := make(map[string]string) 15 m := &MyProfileForm{} 16 m.SetPrefillFields(prefillFields) 17 m.SetFields(fields) 18 m.SetErrors(errors) 19 m.SetFormParams(formParams) 20 return m 21 } 22 23 func (m *MyProfileForm) Validate() bool { 24 m.RegenerateErrors() 25 m.PopulateFields() 26 27 // Check if the about text box was filled out 28 if isokit.FormValue(m.FormParams(), "aboutTextArea") == "" { 29 m.SetError("aboutTextArea", "The about text box is required.") 30 } 31 32 // Check if the location field was filled out 33 if isokit.FormValue(m.FormParams(), "locationInput") == "" { 34 m.SetError("locationInput", "The location field is required.") 35 } 36 37 // Check if the interests field was filled out 38 if isokit.FormValue(m.FormParams(), "interestsInput") == "" { 39 m.SetError("interestsInput", "The interests field must be filled.") 40 } 41 42 if len(m.Errors()) > 0 { 43 return false 44 45 } else { 46 return true 47 } 48 }