-
Notifications
You must be signed in to change notification settings - Fork 6
/
contact.go
58 lines (47 loc) · 1.49 KB
/
contact.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package forms
import (
"github.com/EngineerKamesh/igb/igweb/shared/validate"
"go.isomorphicgo.org/go/isokit"
)
type ContactForm struct {
isokit.BasicForm
}
func NewContactForm(formParams *isokit.FormParams) *ContactForm {
prefillFields := []string{"firstName", "lastName", "email", "messageBody"}
fields := make(map[string]string)
errors := make(map[string]string)
c := &ContactForm{}
c.SetPrefillFields(prefillFields)
c.SetFields(fields)
c.SetErrors(errors)
c.SetFormParams(formParams)
return c
}
func (c *ContactForm) Validate() bool {
c.RegenerateErrors()
c.PopulateFields()
// Check if first name was filled out
if isokit.FormValue(c.FormParams(), "firstName") == "" {
c.SetError("firstName", "The first name field is required.")
}
// Check if last name was filled out
if isokit.FormValue(c.FormParams(), "lastName") == "" {
c.SetError("lastName", "The last name field is required.")
}
// Check if message body was filled out
if isokit.FormValue(c.FormParams(), "messageBody") == "" {
c.SetError("messageBody", "The message area must be filled.")
}
// Check if e-mail address was filled out
if isokit.FormValue(c.FormParams(), "email") == "" {
c.SetError("email", "The e-mail address field is required.")
} else if validate.EmailSyntax(isokit.FormValue(c.FormParams(), "email")) == false {
// Check e-mail address syntax
c.SetError("email", "The e-mail address entered has an improper syntax.")
}
if len(c.Errors()) > 0 {
return false
} else {
return true
}
}