func (f *Form) AddInDisplayGroup(groupname string, items []string) error { if len(items) <= 0 { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Empty group cannot be added %s:%s:%d:\n", filename, callingfuncname, line) return errors.New(err) } if _, present := f.Displaygroups[groupname]; !present { f.Displaygroups = make(map[string][]string, 0) } //iterate and check if any invalid group was passed for _, itm := range items { var exists = false for grp, _ := range f.Group { if grp == itm { exists = true break } } //if an invalid group was passed return error if !exists { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Non existent group name <%s> cannot be added %s:%s:%d:\n", itm, filename, callingfuncname, line) return errors.New(err) } } f.Displaygroups[groupname] = items return nil }
func (f *Form) SetMethod(method string) error { if method == "" { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Expected GET or POST received null instead from %s:%s:%d:\n", filename, callingfuncname, line) return errors.New(err) } isValidMethod := stringarray.In_Array(strings.ToUpper(method), formmethods[:]) //check if a valid position name was passed ex: first, last etc if !isValidMethod { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Expected GET or POST received %s instead from %s:%s:%d:\n", method, filename, callingfuncname, line) return errors.New(err) } f.Method = strings.ToUpper(method) return nil }
func (s *Select) SetMultiOptionAttribs(attribname string, attribs []string) error { if len(s.Options) == 0 { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Attribs cannot be set when they are no options %s:%s:%d:\n", filename, callingfuncname, line) return errors.New(err) } if len(s.Options) != len(attribs) { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Size of Options and Attribs do not match %d=%d %s:%s:%d:\n", len(s.Options), len(attribs), filename, callingfuncname, line) return errors.New(err) } optionattrib[attribname] = attribs return nil }
func NewForm(name string, action string) (*Form, error) { if name == "" { filename, callingfuncname, line := formerror.HandleDepth(2) var err = fmt.Sprintf("Expected form name, received null instead: %s : %s :%d\n", filename, callingfuncname, line) return nil, errors.New(err) } f := &Form{Name: name} if action != "" { f.Action = action } f.Method = formmethods[1] //default is post method return f, nil }