HTML Form tag generation

package salt\view

 Methods

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

Return a checkbox HTML tag with a 1/0 implementation.

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

Unchecked box will return 0 and not an unset name like standard checkbox

This tag work with and without javascript
With javascript, if you set the checkbox value (to one of 1/0), you need jQuery AND call change() after val(...)

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

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\Converter $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\Converter

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

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 (simple name, not the return of self::getName() !)

Exceptions

\salt\SaltException if called outside a form

Returns

mixedvalue in GET/POST for this name, with nameContainer support

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

Register a javascript bloc executed when page was loaded. Require IE9+ or real browser ;o)

registerJSPageLoaded() : string
Static

Returns

stringthe javascript key

Add a value for a replaceable token in JS code registered to registerJavascript()

registerJSTokenValue(string $key, string $value, string $valueKey = NULL, string $tokenSeparator = "\n") : string
Static

Parameters

$key

string

The key of registerJavascript()

$value

string

Value to use for replace {$key}

$valueKey

string

key for value, multiple call with same key replace the value

$tokenSeparator

string

separator for muliple values

Returns

string$valueKey

Register a javascript bloc to add before closing form

registerJavascript(string $key, string $jsCode) : string
Static

Parameters

$key

string

The key to use for append code : every previous code registered with this key is replaced

$jsCode

string

The javascript code

Returns

stringthe $key

Return a select HTML tag

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

Parameters

$name

string

name of the tag

$options

array<mixed,mixed>

all possible values in one of theses formats :

  • key=>value
  •     
  • key=>array('value' => displayValue, 'attr' => attrValue, ...)
  • group_label=>array('group' => array(key=>value))
  • group_label=>array('group' => array(key=>array('value' => displayValue, 'attr' => attrValue, ...)))

$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

Replace value from previously submitted form

setValue(string $name, mixed $value) 
Static

Parameters

$name

string

name of input (simple name, not the return of self::getName() !)

$value

mixed

value to set

Exceptions

\salt\SaltException if called outside a form

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 use of improved checkbox in FORM method for boolean fields

useImprovedCheckbox(string $value = TRUE
Static

Improved checkbox use jQuery for handle a checkbox mapped to a hidden select field with 0 et 1 values

Parameters

$value

string

FALSE for disable improved checkbox

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

Build options tag of a select input

buildSelectOptions(array<mixed,mixed> $options, mixed $selected) : string
Static

Parameters

$options

array<mixed,mixed>

all possible values in one of theses formats :

  • key=>value
  •     
  • key=>array('value' => displayValue, 'attr' => attrValue, ...)
  • group_label=>array('group' => array(key=>value))
  • group_label=>array('group' => array(key=>array('value' => displayValue, 'attr' => attrValue, ...)))

$selected

mixed

selected value(s)

Returns

stringHTML text for $options

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

Build an HTTP query from an associative array like http_build_query

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

Improved http_build_query : parameters with NULL value will be converted to "?parameter"

see

Parameters

$params

array<mixed,mixed>

Returns

stringquery string

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

 

List of javascript code to add before closing form

$javascriptCodes : array<mixed,string>

Default

array()
Static
 

List of javascript token values to use for replace {jsKey} in javascript code, as array(value, token separator)

$javascriptTokens : array<mixed,string>

Default

array()
Static
 

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
 

TRUE for use improved checkbox with FORM method for boolean fields

$useImprovedCheckbox : boolean

Default

TRUE
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 format

FORMAT_KEY = 'format' 
 

Key for adding datepicker JS

PARAM_DATEPICKER = '_saltDatePicker' 
 

Raw format

RAW = 'raw' 
 

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