cheikhshift / form

Create HTML forms with your structs and interfaces.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go-Form

Create HTML forms with your structs and interfaces.

Requirements

Install and import

Add these tags within your .gxml file.

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

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 with AngularJS

Build a new form compatible with Angular using the following template pipeline :

{{ AngularForm $arg1 $arg2 $arg3 $arg4 $arg5 .Session }}

Argument information :

  • $arg1 : Interface{} - Interface to build form with. Submit a variable with data to prepopulate form.
  • $arg2 : String - Target URL to submit form to. This is used to generate a token only valid for the specified target URL path.
  • $arg3 : String - JS Function to use with form's submit ng-click .
  • $arg4 : Call to action of form button.
  • $arg5 : String - variable name to be used as a local scope object to hold form data.
  • .Session : *sessions.Session - Current user session. Must be passed to ensure secure communication.

How to use

Build a new form within a Golang server template:

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

Argument information :

  • $arg1 : Interface{} - Interface to build form with. Submit a variable with data to prepopulate form.
  • $arg2 : String - Target URL to submit form to.
  • $arg3 : String - Method of form submission (GET,POST,PUT etc...).
  • $arg4 : String - Call to action of form button.
  • .Session : *sessions.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.

11. Password

Display password 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>

About

Create HTML forms with your structs and interfaces.

License:GNU Lesser General Public License v2.1


Languages

Language:Go 100.0%