simpleform

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: MIT Imports: 4 Imported by: 1

README

SimpleForm Build Status GoDoc Go Report Card

SimpleForm is a language for constructing HTML forms out of very little text.

Here's a simple login form:

Login

Welcome dear user!

Username: {{ username }}
Password: {{ password }}

[Login](/login)
  • The first line is recognized as the title, and is used both for the title (like this: <title>Login</title> and as a title in the body, like this: <h2>Login</h2>.
  • The lines with {{ and }} are recognized as single line input fields, where the label is the word before :.
  • The [Login](/login) is recognized as a button that can submit the contents of the form as a POST request to /login.

Here's the generated output from the above form file:

<!doctype html>
<html lang="en">
  <head>
    <title>Login</title>
  </head>
  <body>
    <h2>Login</h2>
    <p>Welcome dear user!</p>
    <form method="POST">
      <label for="username">Username:</label><input type="text" id="username" name="username"><br><br>
      <label for="password">Password:</label><input type="password" id="password" name="password"><br><br>
      <input type="submit" formaction="/login" value="Login"><br><br>
    </form>
  </body>
</html>

Features and limitations

  • If the input ID starts with password or pwd, then the input type "password" is used.
  • Multiple buttons can be provided on a single line.
  • All text that is not recognized as either the title or as form elements is combined and returned in a <p> tag.
  • If [[ and ]] are used instead of {{ and }}, then a multi-line text input box is created instead.
  • Check boxes and radio buttons are not supported yet.

General Info

Documentation

Index

Constants

View Source
const VersionString = "SimpleForm 0.1.0"

VersionString is the current name and version of this package

Variables

View Source
var (
	// MultilineColumns is the number of columns that multiline input text should have
	MultilineColumns = 80
	// MultilineRows is the number of rows that multiline input text should have
	MultilineRows = 25
)

Functions

func HTML

func HTML(frmContents string, entireDocument bool, options ...string) (string, error)

HTML transforms the contents of a .frm file to a HTML form

Example use:

Return a full HTML document:
  HTML(frmContents, true, "en", "/style.css, "/favicon.ico")

Return just the body of the HTML document, using the default values of the rest:
  HTML(frmContents, false)

If entireDocument is true, doctype + html + head + body is returned, and not just the body contents.

The optional parameter can be from 0 to 3 strings with: - The language of the document, default is "en" - The CSS URL of the document, no default, example: "/css/style.css" - The favicon URL of the document, no default, example: "/img/favicon.ico"

Types

This section is empty.

Directories

Path Synopsis
cmd
frm2html command

Jump to

Keyboard shortcuts

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