Documentation ¶
Overview ¶
Copyright 2012 The GoForms Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Extended by MartinBrugnara (2014) <martin@martin-dev.eu>
Package goforms/forms enables form data validation, cleaning and error collection, similar to Django forms. From forms_test.go:
formFields := FormFields{ "name": fields.NewCharField(fields.Defaults{ "Required": true, }), "age": fields.NewIntegerField(fields.Defaults{ "Required": false, }), "about": fields.NewCharField(fields.Defaults{ "Max": 10, }), } personForm := Form{Fields: formFields} personForm.Data = urls.Values{ "name": {"Michael Nelson"}, "age": {"37"}, } if personForm.IsValid() { doStuffWithCleanedData() // personForm.CleanedData contains cleaned data // (ie. an int for age in this case): // {"name": "Michael Nelson", "age": 37} // so that for required fields you can safely do: // var age int = personForm.CleanedData["age"].(int) } else { doStuffWithErrors() // If personForm.Data = urls.Values{"age": {"Not a number"}}, // then personForm.Errors would be { // "name": "This field is required.", // "age": "The value ust be a valid integer." // } }
You can see more examples in goforms/forms/forms_test.go.
For another form-data processing library, see github.com/gorilla/schema, which fills structs with form data using struct tags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CleanedData ¶
type CleanedData map[string]interface{}
Contains the cleaned data after a call to IsValid().
Click to show internal directories.
Click to hide internal directories.