Documentation ¶
Overview ¶
This package belongs to the form module.
The Types defined in this application packages are meant to be used in your controller to process forms
Index ¶
- func GetUnsubmittedForm(ctx context.Context, r *web.Request, service domain.FormService) (domain.Form, error)
- func ProcessFormRequest(ctx context.Context, r *web.Request, formService domain.FormService) (domain.Form, error)
- func SimpleProcessFormRequest(ctx context.Context, r *web.Request) (domain.Form, error)
- func ValidationErrorsToValidationInfo(err error) domain.ValidationInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUnsubmittedForm ¶
func GetUnsubmittedForm(ctx context.Context, r *web.Request, service domain.FormService) (domain.Form, error)
GetUnsubmittedForm: Use this if you need an unsubmitted form
func ProcessFormRequest ¶
func ProcessFormRequest(ctx context.Context, r *web.Request, formService domain.FormService) (domain.Form, error)
ProcessFormRequest: Parses and Validates a Request to a Form - with the Help of the passed FormService
It calls the ParseFormData() method of the passed formService. Also, in case the form was submitted, it calls ValidateFormData() method of the formService (passing the parsed data)
Validation is only called if request was send via "POST". Also you can skip validation by passing a "novalidate" parameter. (In this cases form.IsSubmitted stays false)
func SimpleProcessFormRequest ¶
SimpleProcessFormRequest: Parses Post Values and returns a Form object with ALL the submitted data as simple map (string of strings) can be used if you dont need or want advanced form processing and validation. This method don't need a "domain.FormService"
Example ¶
package main import ( "fmt" "context" "net/http" "strings" "flamingo.me/flamingo/core/form/application" "flamingo.me/flamingo/framework/web" ) func main() { httpRequest, _ := http.NewRequest("POST", "?test=demo", strings.NewReader("")) flamingoWebRequest := web.RequestFromRequest(httpRequest, nil) form, _ := application.SimpleProcessFormRequest(context.Background(), flamingoWebRequest) fmt.Printf("%v\n", form.IsSubmitted) fmt.Print(form.Data.(map[string]string)["test"]) }
Output: true demo
func ValidationErrorsToValidationInfo ¶
func ValidationErrorsToValidationInfo(err error) domain.ValidationInfo
ValidationErrorsToValidationInfo
Use this if you want to convert a error object to the domain.ValidationInfo ¶
Its main purpose is to be used with the package @see gopkg.in/go-playground/validator.v9 (InvalidValidationError / ValidationErrors )
Example ¶
type ( CustomerEditFormData struct { FirstName string `validate:"required"` LastName string `validate:"required"` Title string `` } ) formData := CustomerEditFormData{} //validate - result from package validator "gopkg.in/go-playground/validator.v9" validate := validator.New() result := application.ValidationErrorsToValidationInfo(validate.Struct(formData)) fmt.Printf("%v\n", result.IsValid) fmt.Printf(result.FieldErrors["firstName"][0].MessageKey)
Output: false formerror_firstName_required
Types ¶
This section is empty.