Documentation

GRIS_FORM
in package

Class for html forms

With this class forms can be created and elements can be added very flexible

PHP version 7

Copyright (c) 2012, Holger Heuser, GESIS Leibniz Institute for the Social Sciences Unter Sachsenhausen 6-8 50667 Cologne, Germany

Tags
copyright

Copyright (c) 2012, Holger Heuser, GESIS Leibniz Institute for the Social Sciences

link

GESIS Leibniz Institute for the Social Sciences

since
1

File available since Release 1.0

version
1.0
author

Holger Heuser holger.heuser@gesis.org

Table of Contents

settings_group  = "form"
The constant for the settings group
$form  : array<string|int, mixed>
The array for the lines of the form
$form_name  : string
The name of the form (also used to name the class and id)
$form_wrap  : array<string|int, mixed>
The array of tags wrapped around the form
$i18n  : object
The i18n object
$logger  : object
The object for logs
$margin  : string
The margin between the form elements (Bootstrap 5 margin class)
$margin_small  : string
The smaller margin between the form elements (Bootstrap 5 margin class)
$settings  : object
The object for settings
$template  : object
The object for templates
__construct()  : mixed
The class constructor
add_button()  : bool
Adds a button to the form array
add_checkbox()  : bool
Adds a set of checkboxes to the form array
add_form()  : bool
Creates the the attributes and wraps for the form element
add_html()  : bool
Adds plain html the form array
add_info()  : string
Adds an information symbol to an element
add_input()  : bool
Adds an input fields to the form array
add_radio()  : bool
Adds a set of radiobuttons to the form array
add_select()  : bool
Adds a selection to the form array
add_tag()  : bool
Adds a single tag to the form array
add_text()  : bool
Adds text or html to the form array and wraps it with a special tag if param is set
add_textarea()  : bool
Adds a text area to the form array
get_form()  : string
Returns the whole form as string or a direct html output <a href="GRIS_FORM.php">GRIS_FORM.php</a>
pop()  : string
Returns and removes the last entry from the form array
add_label()  : string
Adds a label to a given form element

Constants

settings_group

The constant for the settings group

public mixed settings_group = "form"

Properties

$form

The array for the lines of the form

private array<string|int, mixed> $form
Tags
access

private

$form_name

The name of the form (also used to name the class and id)

private string $form_name
Tags
access

private

$form_wrap

The array of tags wrapped around the form

private array<string|int, mixed> $form_wrap
Tags
access

private

$i18n

The i18n object

private object $i18n
Tags
access

private

$logger

The object for logs

private object $logger
Tags
access

private

$margin

The margin between the form elements (Bootstrap 5 margin class)

private string $margin
Tags
access

private

$margin_small

The smaller margin between the form elements (Bootstrap 5 margin class)

private string $margin_small
Tags
access

private

$settings

The object for settings

private object $settings
Tags
access

private

$template

The object for templates

private object $template
Tags
access

private

Methods

__construct()

The class constructor

public __construct(string $name[, bool $compact = false ]) : mixed

Initializes the form

Parameters
$name : string

The name of the form

$compact : bool = false

Use smaller margin for the whole form

Return values
mixed

add_button()

Adds a button to the form array

public add_button(array<string|int, mixed> $params) : bool
Parameters
$params : array<string|int, mixed>

The parameters for the element

Return values
bool

true

add_checkbox()

Adds a set of checkboxes to the form array

public add_checkbox(array<string|int, mixed> $checkboxes[, bool $compact = true ][, string $button = NULL ]) : bool

For checkbox "label" => "value"

Available params: div_class, onChange

Available prefixes for the options array (standalone or in combinations in strict order as listed below):

  • for checked item

for disabled item

  • for required item
Parameters
$checkboxes : array<string|int, mixed>

The parameters for the element

$compact : bool = true

Use smaller margins for checkbox groups

$button : string = NULL

Additional button for the input (e. g. an "add" button)*

Return values
bool

true

add_form()

Creates the the attributes and wraps for the form element

public add_form(string $action[, string $method = NULL ][, bool $no_form = false ][, bool $validation = true ][, string $enctype = NULL ]) : bool
Parameters
$action : string

The action after submission

$method : string = NULL

The method for the form (GET/POST)

$no_form : bool = false

Don't wrap the elements with a form tag

$validation : bool = true

Activate bootstrap features for form validation

$enctype : string = NULL

The encoding type (default is no param)

Return values
bool

true

add_html()

Adds plain html the form array

public add_html(string $html) : bool
Parameters
$html : string

The html code

Return values
bool

true

add_info()

Adds an information symbol to an element

public add_info(string $name[, mixed $float = true ]) : string
Parameters
$name : string

The name of the element

$float : mixed = true
Return values
string

The hmtl code for the info symbol

add_input()

Adds an input fields to the form array

public add_input(array<string|int, mixed> $params[, string $label = NULL ][, string $button = NULL ][, string $description = "" ]) : bool
Parameters
$params : array<string|int, mixed>

The parameters for the element

$label : string = NULL

The label for the element

$button : string = NULL

Additional button for the input (e. g. an "add" button)

$description : string = ""

A description text for the field

Return values
bool

true

add_radio()

Adds a set of radiobuttons to the form array

public add_radio(array<string|int, mixed> $radio[, array<string|int, mixed> $compact = true ]) : bool

For radiobutton "label" => "value"

Available params: div_class, onChange, name, required

Available prefixes for the options array (standalone or in combinations in strict order as listed below):

  • for checked item

for disabled item

Parameters
$radio : array<string|int, mixed>

The parameters for the element

$compact : array<string|int, mixed> = true

Use smaller margins for radio button groups

Return values
bool

true

add_select()

Adds a selection to the form array

public add_select(array<string|int, mixed> $params, array<string|int, mixed> $options[, string $label = NULL ][, bool $sort = true ][, array<string|int, mixed> $optiondata = array() ][, string $button = NULL ]) : bool

For options "key" => "value"

Available params: class, div_class, name, inline_text, inline_text_id, required

Available prefixes for the options array (standalone or in combinations in strict order as listed below): * for selected item # for disabled item

For optgroups (key has to be numbered from 1 to 9) "%optgroup1" => "Name of optgroup" "%/optgroup1" => ""

Parameters
$params : array<string|int, mixed>

The parameters for the element

$options : array<string|int, mixed>

The options for the selection

$label : string = NULL

The label for the element

$sort : bool = true

Sort options alphabetically

$optiondata : array<string|int, mixed> = array()

Additional data-attributes for options (same key names as $options required, but individual keys can be omitted)

$button : string = NULL

Additional button for the input (e. g. an "add" button)*

Return values
bool

true

add_tag()

Adds a single tag to the form array

public add_tag(string $tag[, string $close = false ][, string $class = NULL ]) : bool
Parameters
$tag : string

The tag

$close : string = false

Param wether the tag should be opened or closed (true for closed)

$class : string = NULL

An optional css class

Return values
bool

true

add_text()

Adds text or html to the form array and wraps it with a special tag if param is set

public add_text(string $text[, string $tag = "" ][, string $wrap = NULL ][, string $params = NULL ][, string $class = NULL ][, string $id = NULL ]) : bool
Parameters
$text : string

The text or valid html

$tag : string = ""

The optional tag to wrap the text

$wrap : string = NULL

Wrap the text or html with the default form element tag. Use "wrap" for full wrap or "open" and "close" for single tag. Leave blank for no wrap.

$params : string = NULL

Optional params for the tag (e. g. class oder id)

$class : string = NULL

Optional class for the outer wrap

$id : string = NULL

Optional ID for the outer wrap

Return values
bool

true

add_textarea()

Adds a text area to the form array

public add_textarea(array<string|int, mixed> $params, string $text[, string $label = NULL ][, bool $editor = false ][, string $description = "" ][, string $button = NULL ]) : bool
Parameters
$params : array<string|int, mixed>

The parameters for the element

$text : string

The text

$label : string = NULL

The label for the element

$editor : bool = false

Use a wysiwig editor for the textarea (default is false)

$description : string = ""

A description text for the field

$button : string = NULL

Additional button for the input (e. g. an "add" button)

Return values
bool

true

get_form()

Returns the whole form as string or a direct html output <a href="GRIS_FORM.php">GRIS_FORM.php</a>

public get_form([string $type = NULL ]) : string
Parameters
$type : string = NULL

The return type of the form (html or array)

Return values
string

$content The form as a string or an array

pop()

Returns and removes the last entry from the form array

public pop() : string
Return values
string

add_label()

Adds a label to a given form element

private add_label(string $for, string $label[, string $required = "" ][, mixed $class = NULL ]) : string
Parameters
$for : string

The name of the form element

$label : string

The text for the label

$required : string = ""

Symbol for required element

$class : mixed = NULL
Return values
string

The label code

Search results