Categorygithub.com/cheikhshift/form
modulepackage
0.2.1
Repository: https://github.com/cheikhshift/form.git
Documentation: pkg.go.dev

# README

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>

# Functions

Asset loads and returns the asset for the given name.
AssetDir returns the file names below a certain directory embedded in the file by go-bindata.
AssetInfo loads and returns the asset info for the given name.
AssetNames returns the names of the assets.
No description provided by the author
No description provided by the author
No description provided by the author
decrypt from base64 to decrypted string.
No description provided by the author
No description provided by the author
Parse form from request and set data to specified pointer.
Returns form token.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Access you .gxml's end tags with this http.HandlerFunc.
MustAsset is like Asset but panics when Asset would return an error.
.
No description provided by the author
Return string of Angular form Argument 1 : Interface{} - Interface to build form with.
.
No description provided by the author
No description provided by the author
.
.
.
.
Return HTML form Argument 1 : Interface{} - Interface to build form with.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
.
Return string of form token.
.
No description provided by the author
No description provided by the author
.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
.
.
No description provided by the author
No description provided by the author
RestoreAsset restores an asset under the given directory.
RestoreAssets restores an asset under the given directory recursively.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Returns bool : Verifies if request is valid.

# Constants

select opts,placeholder,title.

# Variables

string : Default submit button attribute class of generated HTML forms.
string : Secret form key .
string : Default input classes of generared HTML input class attribute.
Mb.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

Display Date input.
Display Email input.
Handle file upload.
Display textarea.
Display Passworld input.
Display radio input.
Display dropdown.
Display dropdown list with multiple selection support.