27 lines
445 B
Go
27 lines
445 B
Go
|
package forms
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
)
|
||
|
|
||
|
// Form creates a custom form struct, embeds a url.Values object
|
||
|
type Form struct {
|
||
|
url.Values
|
||
|
Errors errors
|
||
|
}
|
||
|
|
||
|
// New initializes a form struct
|
||
|
func New(data url.Values) *Form {
|
||
|
return &Form{
|
||
|
data,
|
||
|
errors(map[string][]string{}),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Has checks if form field is in post and not emtpy
|
||
|
func (f *Form) Has(field string, r *http.Request) bool {
|
||
|
x := r.Form.Get(field)
|
||
|
return x != ""
|
||
|
}
|