HTML Form tag generation

package salt\view

 Methods

Return a HTML form close tag

end() : string
Static

Returns

stringHTML end form tag

Get a HTML tag for modify a field

field(\salt\Field $field, string $name, mixed $value, array<mixed,string> $classes = array(), array<mixed,mixed> $others = array(), \salt\ViewHelper $helper = NULL) : string
Static

For a HTML tag of an existing DAO object, use $dao->FORM->$field instead

Parameters

$field

\salt\Field

the field

$name

string

name of the HTML tag, can be NULL for use the $field->name

$value

mixed

Have to be in DAO format (timestamp for date, TRUE/FALSE for boolean, etc...)

$classes

array<mixed,string>

CSS classes. Each element can contains multiple classes separated by space

$others

array<mixed,mixed>

others HTML attributes : key=>value

$helper

\salt\ViewHelper

The helper to use for format the value

Returns

stringHTML tag for the field

Create a form with GET method.

get(string $action = NULL, array<mixed,mixed> $params = array(), array<mixed,mixed> $others = array()) : string
Static

Parameters

$action

string

Page to send form, NULL for reuse current page

$params

array<mixed,mixed>

List of parameters to add in hidden input. Can be name => value or just name for reusing value in current query.
If name is "*", all parameters in current query are reused.
Example : array('a', 'b'=>2, 'c'=>3) with query a=0&b=1&d=4 will produce hidden inputs :

  • a with value 0 (reuse query value)
  • b with value 2 (override query value)
  • c with value 3 (new parameter)
    d is not specified, so it is not included.

$others

array<mixed,mixed>

Other attributes to add in form tag

Returns

stringHTML form tag

Return an input HTML tag

input(string $name, string $type = 'text', string $value = NULL, array<mixed,string> $classes = array(), array<mixed,mixed> $others = array()) : string
Static

Parameters

$name

string

name of the tag

$type

string

value of type attribute

$value

string

value of the tag

$classes

array<mixed,string>

CSS classes of the tag

$others

array<mixed,mixed>

all other attributes for the tag

Returns

stringHTML text tag

Create a form with POST method.

post(string $action = NULL, array<mixed,mixed> $params = array(), array<mixed,mixed> $others = array()) : string
Static

Parameters

$action

string

Page to send form, NULL for reuse current page

$params

array<mixed,mixed>

List of parameters to add in method URL. Can be name => value or just name for reusing value in current query.
If name is "*", all parameters in current query are reused.
Example : array('a', 'b'=>2, 'c'=>3) with query a=0&b=1&d=4 will produce method="...?a=0&b=2&c=3"

  • a with value 0 (reuse query value)
  • b with value 2 (override query value)
  • c with value 3 (new parameter)
    d is not specified, so it is not included.

$others

array<mixed,mixed>

Other attributes to add in form tag

Returns

stringHTML form tag

Return a list of radio HTML tag

radio(string $name, string $options, string $value = NULL, array<mixed,string> $classes = array(), array<mixed,mixed> $others = array()) : array<mixed,string>
Static

Parameters

$name

string

name of the tag

$options

string

all possible values key=>value

$value

string

value of the tag

$classes

array<mixed,string>

CSS classes of the tag

$others

array<mixed,mixed>

all other attributes for the tag

Returns

array<mixed,string>HTML text tag

Return a select HTML tag

select(string $name, string $options, string $value = NULL, array<mixed,string> $classes = array(), array<mixed,mixed> $others = array()) : string
Static

Parameters

$name

string

name of the tag

$options

string

all possible values key=>value

$value

string

value of the tag

$classes

array<mixed,string>

CSS classes of the tag

$others

array<mixed,mixed>

all other attributes for the tag

Returns

stringHTML text tag

Return a textarea HTML tag

textarea(string $name, string $value = NULL, array<mixed,string> $classes = array(), array<mixed,mixed> $others = array()) : string
Static

Parameters

$name

string

name of the tag

$value

string

value of the tag

$classes

array<mixed,string>

CSS classes of the tag

$others

array<mixed,mixed>

all other attributes for the tag

Returns

stringHTML text tag

Enable or disable usage of JQueryUI

withJQueryUI(boolean $value = TRUE
Static

Parameters

$value

boolean

TRUE (default) for enable JQueryUI, false for disable

Set a name template for all names generated by next tags

withNameContainer(string $name) 
Static

Parameters

$name

string

... $name all names containers : (a, b, c) will give a[b][c][component_name]

Stopping use a name template

withoutNameContainer() 
Static

Get a HTML tag

HTMLtag(string $tagName, array $attributes, string $content = NULL, integer $tagType = self::TAG_FULL) : string
Static

Parameters

$tagName

string

name of the HTML tag

$attributes

array

attributes of the tag

$content

string

content of tag : Have to be an escaped HTML String

$tagType

integer

type of tag : self::TAG_*

Returns

stringHTML tag

Compute tag attributes

commonTagAttributes(string $name, string $value, array<mixed,string> $classes, array<mixed,mixed> $attrs) : array<mixed,mixed>
Static

Parameters

$name

string

name of the tag

$value

string

value of the tag

$classes

array<mixed,string>

array of CSS classes, each element can contain multiple classes separated by spaces

$attrs

array<mixed,mixed>

all others attributes : key=>value

Returns

array<mixed,mixed>attributes to use in tag : key=>value

Get real name to use, if nameContainer is defined

getName(string $name) : string
Static

Parameters

$name

string

simple tag/field name

Returns

string$name or $name in template if we use withNameContainer()

Get value from previously submitted form

getValue(string $name) : mixed
Static

Parameters

$name

string

name of input

Exceptions

\salt\SaltException if called outside a form

Returns

mixedvalue in GET/POST for this name

Compute new parameters list for form tag

parseParams(string $query, array<mixed,string> $params) : array<mixed,string>
Static

Parameters

$query

string

Query of URL in QUERY_STRING format : var1=value1&var2=value2...

$params

array<mixed,string>

List of varX to keep or redefine. '*' for reuse all request parameters, key=>NULL for remove key parameter

Returns

array<mixed,string>key=>value

 Properties

 

G or P character, for GET/POST

$method : string

Default

NULL
Static
 

pattern for naming tags. Character '?' is replaced by last tag name

$nameContainer : string

Default

NULL
Static
 

GET/POST values

$values : array<mixed,mixed>

Default

NULL
Static
content if nameContainer is used, contains GET/POST values that are resolved early for retrieve form values.
 

TRUE if we can use JQueryUI decoration on form tags

$withJQueryUI : boolean

Default

TRUE
Static

 Constants

 

Key for store value before formatting

PARAM_RAW_VALUE = '_saltRawValue' 
 

Tag type : Close tag only

TAG_CLOSE = 2 
 

Tag type : Open and close tag

TAG_FULL = 0 
 

Tag type : Open tag only

TAG_OPEN = 1