Documentation ¶
Index ¶
- Constants
- Variables
- type Button
- type Checkbox
- type DateInput
- func (i DateInput) AutoFill() []string
- func (i DateInput) Fill(val string) (value string, ok bool)
- func (i DateInput) Multipart() bool
- func (i DateInput) Multiple() bool
- func (i DateInput) Name() string
- func (i DateInput) Options() (values []string)
- func (i DateInput) Required() bool
- func (i DateInput) Type() string
- func (i DateInput) Value() string
- func (i DateInput) Values() []string
- type Document
- type EmailInput
- func (i EmailInput) AutoFill() []string
- func (i EmailInput) Multipart() bool
- func (i EmailInput) Multiple() bool
- func (i EmailInput) Name() string
- func (i EmailInput) Options() (values []string)
- func (i EmailInput) Required() bool
- func (i EmailInput) Type() string
- func (i EmailInput) Value() string
- func (i EmailInput) Values() []string
- type FileInput
- func (f FileInput) AutoFill() (values []string)
- func (f FileInput) Fill(val string) (value string, ok bool)
- func (f FileInput) Multipart() bool
- func (i FileInput) Multiple() bool
- func (i FileInput) Name() string
- func (i FileInput) Options() (values []string)
- func (i FileInput) Required() bool
- func (i FileInput) Type() string
- func (i FileInput) Value() string
- func (i FileInput) Values() []string
- type Form
- func (e *Form) Err() error
- func (f Form) GetOptionsFor(name string) (options []string)
- func (f Form) GetParams(opts ...Option) (string, error)
- func (f Form) IsRequired(name string) bool
- func (f Form) MultipartParams(opts ...Option) (boundary string, data []byte, err error)
- func (f Form) NewRequest(opts ...Option) (*http.Request, error)
- func (f Form) NewTestRequest(opts ...Option) (*http.Request, error)
- func (f Form) PostParams(opts ...Option) ([]byte, error)
- func (f Form) Testing(t test) TestingForm
- func (f Form) Validate(opts ...Option) error
- type Forms
- type HiddenInput
- func (i HiddenInput) AutoFill() (values []string)
- func (i HiddenInput) Fill(val string) (value string, ok bool)
- func (i HiddenInput) Multipart() bool
- func (i HiddenInput) Multiple() bool
- func (i HiddenInput) Name() string
- func (i HiddenInput) Options() (values []string)
- func (i HiddenInput) Required() bool
- func (i HiddenInput) Type() string
- func (i HiddenInput) Value() string
- func (i HiddenInput) Values() []string
- type Input
- type Inputs
- type NumberInput
- func (i NumberInput) AutoFill() []string
- func (i NumberInput) Fill(val string) (value string, ok bool)
- func (i NumberInput) Multipart() bool
- func (i NumberInput) Multiple() bool
- func (i NumberInput) Name() string
- func (i NumberInput) Options() (values []string)
- func (i NumberInput) Required() bool
- func (i NumberInput) Type() string
- func (i NumberInput) Value() string
- func (i NumberInput) Values() []string
- type Option
- func Add(name string, value string) Option
- func AddFile(fieldname string, filename string, contents []byte) Option
- func AutoFill() Option
- func Click(buttonValue string) Option
- func Reset(name string) Option
- func Set(name string, value string) Option
- func UnsafeSet(name string, value string) Option
- func WithContext(ctx context.Context) Option
- type Radio
- type Select
- type TestingForm
- type TextInput
- func (i TextInput) AutoFill() (value []string)
- func (i TextInput) Fill(val string) (value string, ok bool)
- func (i TextInput) Multipart() bool
- func (i TextInput) Multiple() bool
- func (i TextInput) Name() string
- func (i TextInput) Options() (values []string)
- func (i TextInput) Required() bool
- func (i TextInput) Type() string
- func (i TextInput) Value() string
- func (i TextInput) Values() []string
- type URLInput
- func (i URLInput) AutoFill() []string
- func (i URLInput) Multipart() bool
- func (i URLInput) Multiple() bool
- func (i URLInput) Name() string
- func (i URLInput) Options() (values []string)
- func (i URLInput) Required() bool
- func (i URLInput) Type() string
- func (i URLInput) Value() string
- func (i URLInput) Values() []string
Constants ¶
const ( ElementSelect = "select" ElementInput = "input" ElementButton = "button" ElementTextArea = "textarea" InputTypeText = "text" InputTypeFile = "file" InputTypeCheckbox = "checkbox" InputTypeRadio = "radio" InputTypeHidden = "hidden" InputTypeSubmit = "submit" InputTypeEmail = "email" InputTypeURL = "url" InputTypeDate = "date" InputTypeNumber = "number" )
const ( AutoFillEmail = "test@example.com" AutoFillURL = "https://www.example.com" ISO8601Date = "2006-01-02" AutoFillDate = ISO8601Date )
const ContentTypeForm = "application/x-www-form-urlencoded"
const ContentTypeMultipart = "multipart/form-data"
Variables ¶
var AutoFillFile = []byte{0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf}
var PatternEmail = regexp.MustCompile("[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$")
var PatternURL = regexp.MustCompile("^https?://.+")
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
func ParseWithURL ¶
Parse all formsr in the HTML document and set the default URL if <form action="..."> attribute is missing
func (Document) FindFormsByClass ¶
type EmailInput ¶
type EmailInput struct {
TextInput
}
func (EmailInput) AutoFill ¶
func (i EmailInput) AutoFill() []string
type Form ¶
type Form struct { // All html attributes of the form. Used to find the form by attribute Attr []html.Attribute ClassList []string // Value of Enctype attribute, default is application/x-www-form-urlencoded. // For forms with file uploads it should be multipart/form-data. ContentType string // All found inputs Inputs Inputs // Value of form method attribute Method string // Value form action attribute URL string // All found <button type="submit"> and <input type="submit"> elements. Buttons []Button // contains filtered or unexported fields }
func (Form) GetOptionsFor ¶
Returns a list of available input values for elements with options (checkbox, radio or select).
func (Form) IsRequired ¶
Returns true if field is required, false otherwise.
func (Form) MultipartParams ¶
Fills the form and returns parameters for a multipart request. If there was any error in the parsing or if the form was filled incorrectly, it will return an error.
func (Form) NewRequest ¶
Fills the form and returns a new request. If there was any error in the parsing or if the form was filled incorrectly, it will return an error.
func (Form) NewTestRequest ¶
Fills the form and returns a new test request. If there was any error in the parsing or if the form was filled incorrectly, it will return an error.
func (Form) PostParams ¶
Fills the form and returns body for a POST request.
func (Form) Testing ¶
func (f Form) Testing(t test) TestingForm
type HiddenInput ¶
type HiddenInput struct {
// contains filtered or unexported fields
}
type NumberInput ¶
type NumberInput struct {
// contains filtered or unexported fields
}
func (NumberInput) AutoFill ¶
func (i NumberInput) AutoFill() []string
type Option ¶
type Option func(f *filler) error
func Add ¶
Adds a name=value pair to the form. If there is an empty value it will be replaced, otherwise a second value will be added, but only if the element supports multiple values, like checkboxes or <select multiple> elements.
func Click ¶
Adds the submit buttons name=value combination to the form submission. Useful when there are two or more buttons on a form and their values make a difference on how the server's going to process the form data.
func WithContext ¶
type TestingForm ¶
type TestingForm struct {
// contains filtered or unexported fields
}
func (TestingForm) NewTestRequest ¶
func (f TestingForm) NewTestRequest(opts ...Option) *http.Request