The form interface

An isomorphic web form implements the Form interface found in the isokit package:

type Form interface {
Validate() bool
Fields() map[string]string
Errors() map[string]string
FormParams() *FormParams
PrefillFields()
SetFields(fields map[string]string)
SetErrors(errors map[string]string)
SetFormParams(formParams *FormParams)
SetPrefillFields(prefillFields []string)
}

The Validate method determines if the form has been filled out properly or not, returning a Boolean value of true if the form has been filled out properly, and it returns a Boolean value of false if the form hasn't been filled out properly.

The Fields method returns map of all the form fields where the key is the name of the form field, and the value is the string value of the form field.

The Errors method contains map of all the errors that were populated upon validation of the form. The key is the name of the form field, and the value is a descriptive error message.

The FormParams method returns the form's isomorphic form parameters object. The form parameters object is important because it determines the source from where user entered values for the form fields can be obtained. On the server side, form field values are obtained from *http.Request and on the client-side, form fields are obtained from the FormElement object.

Here's what the FormParams struct looks like:

type FormParams struct {
FormElement *dom.HTMLFormElement
ResponseWriter http.ResponseWriter
Request *http.Request
UseFormFieldsForValidation bool
FormFields map[string]string
}

The PrefillFields method returns a string slice of all the names of the form fields, whose values should be retained in case the user makes a mistake while submitting the form.

The last four getter methods considered, Fields, Errors, FormParams, and PrefillFields, have corresponding settter methods, SetFields, SetErrors, SetFormParams, and SetPrefillFields, respectively.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.93.132