form

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2017 License: LGPL-2.1 Imports: 15 Imported by: 2

README

Go-Form

Create HTML forms with your structs and interfaces.

Requirements
Install and import

Add this tag within your .gxml file.

<import src="github.com/cheikhshift/form/gos.gxml" />	
Configure

Set max upload size :

netform.MaxSize = 20 //mb

Set form token key :

netform.FormKey = "a very very very very secret key"

Set input field class :

netform.InputClass = ""

Set submit button class :

netform.ButtonClass = ""
How to use

Build a new form within a Golang server template:

{{ Build $arg1 $arg2 $arg3 $arg4 .Session }}

Argument information :

  • $arg1 : Interface to build form with. Submit a variable with data to prepopulate form.
  • $arg2 : Target URL to submit form to.
  • $arg3 : Method of form submission.
  • $arg4 : Call to action of form button.
  • .Session : Current user session. Must be passed to ensure secure communication.

Build within <end> tag :

net_Build(param1 interface{}, param2 string, param3 string, param4 string, param5 *sessions.Session) string

Parameter information :

  • param1 : Interface to build form with. Submit a variable with data to prepopulate form.
  • param2 : Target URL to submit form to.
  • param3 : Method of form submission.
  • param4 : Call to action of form button.
  • param5 : Current user session. Must be passed to ensure secure communication.
Server side validation

Please visit the GoValidator page for valuable tag information. here

How to process data.

Within your <end> tag use the following function to validate and convert the post body to the specified interface.

var sampleform SampleForm
err := netform.Form(r, &sampleform)
Field types

List of field types with associated tag behavior.

1. string

Display text input box.

Tag properties :

  • title : title of field.
  • Placeholder : placeholder of field.
2. int | float (any number)

Display number input box.

Tag properties :

  • title : title of field.
  • Placeholder : placeholder of field.
3. bool

Display Checkbox.

Tag properties :

  • title : text blurb right of checkbox.
4. File

Display file upload box. Use this field property with function netform.Pathto get local filesystem path.

Tag properties :

  • Title : title of field.
  • file : Mimetype of file to upload.
5. Paragraph

Display text area.

Tag properties :

  • Title : title of field.
  • Placeholder : placeholder of field.
6. Date

Display date input.

Tag properties :

  • Title : title of field.
  • Placeholder : placeholder of field.
7. Select

Display dropdown list.

Tag properties :

  • Title : title of field.
  • Placeholder : Prompt left of field.
  • select : comma delimited choices of field.
8. SelectMult

Display dropdown list with multiple selection support.

Tag properties :

  • Title : title of field.
  • Placeholder : Prompt left of field.
  • select : comma delimited choices of field.
9. Radio

Display radio input.

Tag properties :

  • Title : title of field.
  • select : comma delimited choices of field.
10. Email

Display email input.

Tag properties :

  • Title : title of field.
  • Placeholder : placeholder of field.
Samples

Sample of GoS <struct/> with form tags set :

<struct name="SampleForm">
		TestField string `title:"Hi world!",valid:"unique",placeholder:"Testfield prompt"`
		Count int `placeholder:"Count"`
		Name string `valid:"required",title:"Input title"`
		FieldTwo netform.Radio `title:"Enter Email",valid:"email,unique,required",select:"blue,orange,red,green"`
		FieldF netform.Select `placeholder:"Prompt?",valid:"email,unique,required",select:"blue,orange,red,green"`
		Created netform.Date
		Text netform.Paragraph 	`title:"Enter a description."`
		Photo netform.File 	`file:"image/*"`
		Emal netform.Email
		Terms bool	`title:"Accept terms of use."`
</struct>

Documentation

Index

Constants

View Source
const (
	MB = 1 << 20
)

select opts,placeholder,title

Variables

View Source
var (
	InputClass  string
	ButtonClass string
	FormKey     = "a very very very very secret key"
	MaxSize     = 10 //Mb
)

Functions

func Decrypt

func Decrypt(key []byte, cryptoText string) string

decrypt from base64 to decrypted string

func Encrypt

func Encrypt(key []byte, text string) string

func Form

func Form(r *http.Request, i interface{}) error

func GenerateToken

func GenerateToken(url string, usertoken string) string

func GetPl

func GetPl(tagstr string) string

func GetSel

func GetSel(tagstr string) string

func Path

func Path(pathtoformat File) string

func SetKey

func SetKey(key string)

func ToBson

func ToBson(data string) bson.M

func ValidateRequest

func ValidateRequest(r *http.Request, usertoken string) bool

Types

type Date

type Date string

type Email

type Email string

type File

type File string

type Paragraph

type Paragraph string

type Radio

type Radio Select

type Select

type Select string

type SelectMult

type SelectMult Select

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL