ValidForm Builder API Documentation

Hidden extends Element
in package

Hidden Class

See ValidForm::addHiddenField()

Example; Add a hidden field to the form

$objForm->addHiddenField("secret-stuff", ValidForm::VFORM_STRING);
Tags
author

Felix Langfeldt [email protected]

author

Robin van Baalen [email protected]

version
5.3.0

Table of Contents

Methods

__call()  : mixed
Magic caller method
__construct()  : mixed
Create new instance
__get()  : mixed
Magic getter method
__getValue()  : string|null
Get the value of the field.
__set()  : mixed
Magic setter method
__toHtml()  : string
Generate HTML output for specific dynamic count
addCondition()  : mixed
Add a new condition to the current field
addField()  : Element
getCondition()  : Condition|null
Get element's Condition object
getConditionRecursive()  : Condition|null
This gets the condition of a given property, just like {@see \ValidFormBuilder\Base::getCondition()}.
getConditions()  : array<string|int, mixed>
Get the conditions collection
getData()  : mixed
Get a value from the internal data array.
getDefault()  : array<string|int, mixed>|string
Get default value
getDynamicButtonMeta()  : mixed
This method determines wheter or not to show the 'add extra field' dynamic button based on it's parent's condition state.
getDynamicCount()  : int
Get the number of dynamic fields from the dynamic counter field.
getDynamicLabelMate()  : array<string|int, mixed>
getDynamicName()  : string
Same as getName() except getDynamicName adds the current dynamic count to the fieldname as a suffix (_1, _2 etc)
getDynamicRemoveLabelMate()  : array<string|int, mixed>
getFieldMeta()  : mixed
Get field meta property.
getHint()  : string
getId()  : string
getLabel()  : string
getLabelMeta()  : string
Get label meta property.
getMagicMeta()  : array<string|int, mixed>
getMagicReservedMeta()  : array<string|int, mixed>
getMeta()  : mixed
Get meta property.
getMetCondition()  : null|Condition
Only get a condition of a given type if that condition is met. If the condition is not met, this returns null
getName()  : string
Return the (original) name of the current field.
getParent()  : Base
getRandomId()  : string
Generate a random ID for a given field name to prevent having two fields with the same name
getRequiredStyle()  : string
getReservedFieldMeta()  : array<string|int, mixed>
getReservedLabelMeta()  : array<string|int, mixed>
getReservedMeta()  : array<string|int, mixed>
getShortLabel()  : string
Get the short label (meta 'summaryLabel') if available.
getTip()  : string
getTipMeta()  : array<string|int, mixed>
getType()  : int
getValidator()  : FieldValidator
getValue()  : mixed
Get the *valid* value of the current field.
hasCondition()  : bool
Check if the current field contains a condition object of a specific type
hasConditions()  : bool
Check if the current object contains any conditions at all.
hasFields()  : bool
Check if field contains child elements
isDynamic()  : bool
Check if the current field is a dynamic field.
isDynamicCounter()  : bool
Check if this hidden field is a dynamic counter
isValid()  : bool
Validate this field
setConditionalMeta()  : mixed
Based on which conditions are met, corresponding metadata is set on the object.
setConditions()  : void
setData()  : bool
Store data in the current object.
setDefault()  : mixed
Set default value on this element
setDynamicCounter()  : mixed
Add a dynamic counter object
setDynamicLabelMeta()  : mixed
Set dynamic label specific meta data
setDynamicRemoveLabelMeta()  : mixed
Set dynamic remove label specific meta data
setError()  : mixed
Set a (custom) error message on this specific element
setFieldMeta()  : mixed
Set field specific meta data
setHint()  : void
setId()  : void
setLabel()  : void
setLabelMeta()  : mixed
Set label specific meta data
setMeta()  : array<string|int, mixed>
Set meta property.
setName()  : void
setParent()  : void
setRequiredStyle()  : void
setTip()  : void
setTipMeta()  : mixed
Set tip specific meta data
setType()  : void
setValidator()  : void
toHtml()  : string
Generate HTML
toJS()  : string
Generate Javascript

Methods

__call()

Magic caller method

public __call(string $method, mixed $values) : mixed
Parameters
$method : string
$values : mixed
Tags
throws
BadMethodCallException

__construct()

Create new instance

public __construct(string $name, int $type[, array<string|int, mixed> $meta = array() ]) : mixed
Parameters
$name : string

The field's name

$type : int

The type is used to validate the hidden field's value

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

The meta array

__get()

Magic getter method

public __get(string $property) : mixed
Parameters
$property : string
Tags
throws
BadMethodCallException

__getValue()

Get the value of the field.

public __getValue([bool $submitted = false ][, int $intDynamicPosition = 0 ]) : string|null

If the value is valid then it will return that value, otherwise the invalid value is returned.

Parameters
$submitted : bool = false

Indicate if the form is submitted.

$intDynamicPosition : int = 0

The position of the field in a dynamic field setup.

Return values
string|null

__set()

Magic setter method

public __set(string $property, mixed $value) : mixed
Parameters
$property : string
$value : mixed
Tags
throws
BadMethodCallException

__toHtml()

Generate HTML output for specific dynamic count

public __toHtml([bool $submitted = false ][, bool $blnSimpleLayout = false ][, bool $blnLabel = true ][, bool $blnDisplayErrors = true ][, int $intCount = 0 ]) : string
Parameters
$submitted : bool = false
$blnSimpleLayout : bool = false
$blnLabel : bool = true
$blnDisplayErrors : bool = true
$intCount : int = 0
Return values
string

addCondition()

Add a new condition to the current field

public addCondition(string $strType, bool $blnValue, array<string|int, mixed> $arrComparisons[, string $intComparisonType = ValidForm::VFORM_MATCH_ANY ]) : mixed

For examples, check Condition

Parameters
$strType : string

Define the condition type. This can be either required, visibile or enabled

$blnValue : bool

Define whether this condition activates if the comparison(s) are true or false.

$arrComparisons : array<string|int, mixed>

An array of Comparison objects

$intComparisonType : string = ValidForm::VFORM_MATCH_ANY

The comparison type. Either ValidForm::VFORM_MATCH_ANY or ValidForm::VFORM_MATCH_ALL. With VFORM_MATCH_ANY, as soon as one of the comparisons validates the condition, the condition is enforced. With ValidForm::VFORM_MATCH_ALL, all of the comparisons must validate before the condition will be enforced.

Tags
throws
Exception

if Condition could not be set

throws
InvalidArgumentException

If invalid arguments are supplied

addField()

public addField() : Element

addField($name, $type, $validationRules = array(), $errorHandlers = array(), $meta = array()) Adds another field to this field if this field is a container

Return values
Element

getCondition()

Get element's Condition object

public getCondition(string $strProperty) : Condition|null

Note: When chaining methods, always use hasCondition() first before chaining for example getCondition()->isMet().

Parameters
$strProperty : string

Condition type e.g. 'required', 'visibile' and 'enabled'

Return values
Condition|null

Found condition or null if no condition is found.

getConditionRecursive()

This gets the condition of a given property, just like {@see \ValidFormBuilder\Base::getCondition()}.

public getConditionRecursive(string $strProperty[, Element $objContext = null ]) : Condition|null

When no condition is found on the current element, the method searches for a condition in it's parent element.

Parameters
$strProperty : string

Condition type e.g. required, visibile and enabled

$objContext : Element = null
Return values
Condition|null

getConditions()

Get the conditions collection

public getConditions() : array<string|int, mixed>
Return values
array<string|int, mixed>

getData()

Get a value from the internal data array.

public getData([string $strKey = null ]) : mixed
Parameters
$strKey : string = null

The key of the data attribute to return

getDefault()

Get default value

public getDefault() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string

getDynamicButtonMeta()

This method determines wheter or not to show the 'add extra field' dynamic button based on it's parent's condition state.

public getDynamicButtonMeta() : mixed

getDynamicCount()

Get the number of dynamic fields from the dynamic counter field.

public getDynamicCount([bool $blnParentIsDynamic = false ]) : int
Parameters
$blnParentIsDynamic : bool = false
Return values
int

The dynamic count of this field

getDynamicLabelMate()

public getDynamicLabelMate() : array<string|int, mixed>

getDynamicLabelMate() Returns the value of $__dynamiclabelmeta

Return values
array<string|int, mixed>

getDynamicName()

Same as getName() except getDynamicName adds the current dynamic count to the fieldname as a suffix (_1, _2 etc)

public getDynamicName([int $intCount = 0 ]) : string

When the dynamic count === 0, the return value equals the output of getName()

Parameters
$intCount : int = 0

The dynamic count

Return values
string

The field name

getDynamicRemoveLabelMate()

public getDynamicRemoveLabelMate() : array<string|int, mixed>

getDynamicRemoveLabelMate() Returns the value of $__dynamicremovelabelmeta

Return values
array<string|int, mixed>

getFieldMeta()

Get field meta property.

public getFieldMeta([string $property = null ][, string $fallbackValue = "" ]) : mixed
Parameters
$property : string = null

Property to get from internal field meta array.

$fallbackValue : string = ""

Optional fallback value if no value is found for requested property

getHint()

public getHint() : string

getHint() Returns the value of $__hint

Return values
string

getId()

public getId() : string

getId() Returns the value of $__id

Return values
string

getLabel()

public getLabel() : string

getLabel() Returns the value of $__label

Return values
string

getLabelMeta()

Get label meta property.

public getLabelMeta([string $property = null ][, string $fallbackValue = "" ]) : string
Parameters
$property : string = null

Property to get from internal label meta array.

$fallbackValue : string = ""

Optional fallback value if requested property has no value

Return values
string

Property value or empty string of none is set.

getMagicMeta()

public getMagicMeta() : array<string|int, mixed>

getMagicMeta() Returns the value of $__magicmeta

Return values
array<string|int, mixed>

getMagicReservedMeta()

public getMagicReservedMeta() : array<string|int, mixed>

getMagicReservedMeta() Returns the value of $__magicreservedmeta

Return values
array<string|int, mixed>

getMeta()

Get meta property.

public getMeta([string $property = null ][, string $fallbackValue = "" ]) : mixed
Parameters
$property : string = null

Property to get from internal meta array.

$fallbackValue : string = ""

Optional fallback value if requested property has no value

getMetCondition()

Only get a condition of a given type if that condition is met. If the condition is not met, this returns null

public getMetCondition(string $strProperty) : null|Condition
Parameters
$strProperty : string

Condition type e.g. 'required', 'visibile' and 'enabled'

Return values
null|Condition

getName()

Return the (original) name of the current field.

public getName() : string

Use getDynamicName() to get the field name + dynamic count

Return values
string

The original field name

getParent()

public getParent() : Base

getParent() Returns the value of $__parent

Return values
Base

getRandomId()

Generate a random ID for a given field name to prevent having two fields with the same name

public getRandomId(string $name) : string
Parameters
$name : string

Field name

Return values
string

getRequiredStyle()

public getRequiredStyle() : string

getRequiredStyle() Returns the value of $__requiredstyle

Return values
string

getReservedFieldMeta()

public getReservedFieldMeta() : array<string|int, mixed>

getReservedFieldMeta() Returns the value of $__reservedfieldmeta

Return values
array<string|int, mixed>

getReservedLabelMeta()

public getReservedLabelMeta() : array<string|int, mixed>

getReservedLabelMeta() Returns the value of $__reservedlabelmeta

Return values
array<string|int, mixed>

getReservedMeta()

public getReservedMeta() : array<string|int, mixed>

getReservedMeta() Returns the value of $__reservedmeta

Return values
array<string|int, mixed>

getShortLabel()

Get the short label (meta 'summaryLabel') if available.

public getShortLabel() : string

Use the 'long' (regular) label as a fallback return value.

Return values
string

The short or regular element label

getTip()

public getTip() : string

getTip() Returns the value of $__tip

Return values
string

getTipMeta()

public getTipMeta() : array<string|int, mixed>

getTipMeta() Returns the value of $__tipmeta

Return values
array<string|int, mixed>

getType()

public getType() : int

getType() Returns the value of $__type

Return values
int

getValue()

Get the *valid* value of the current field.

public getValue([int $intDynamicPosition = 0 ]) : mixed
Parameters
$intDynamicPosition : int = 0

Optional parameter to get the value of a dynamic field.

Return values
mixed

The valid value of this field. If validation fails, it returns null.

hasCondition()

Check if the current field contains a condition object of a specific type

public hasCondition(string $strProperty) : bool
Parameters
$strProperty : string

Condition type e.g. required, visibile and enabled

Return values
bool

True if element has condition object set, false if not

hasConditions()

Check if the current object contains any conditions at all.

public hasConditions() : bool
Return values
bool

True if it contains conditions, false if not.

isDynamic()

Check if the current field is a dynamic field.

public isDynamic() : bool
Return values
bool

True if dynamic, false if not.

isValid()

Validate this field

public isValid([mixed $intCount = null ]) : bool

See Element::isValid()

Parameters
$intCount : mixed = null

Optional. If set, only the dynamic field with this index will be validated.

Tags
see
Element::isValid()
Return values
bool

True if field validates, false if not.

setConditionalMeta()

Based on which conditions are met, corresponding metadata is set on the object.

public setConditionalMeta() : mixed

setConditions()

public setConditions() : void

setConditions(array $value) Overwrites the value of $__conditions

setData()

Store data in the current object.

public setData([string $strKey = null ][, mixed $varValue = null ]) : bool

This data will not be visibile in any output and will only be used for internal purposes. For example, you can store some custom data from your CMS or an other library in a field object, for later use.

Note: Using this method will overwrite any previously set data with the same key!

Parameters
$strKey : string = null

The key for this storage

$varValue : mixed = null

The value to store

Return values
bool

True if set successful, false if not.

setDefault()

Set default value on this element

public setDefault(array<string|int, mixed>|string $varValue) : mixed
Parameters
$varValue : array<string|int, mixed>|string

The value to set as default value

setDynamicCounter()

Add a dynamic counter object

public setDynamicCounter(Element &$objCounter) : mixed
Parameters
$objCounter : Element

setDynamicLabelMeta()

Set dynamic label specific meta data

public setDynamicLabelMeta(string $property, mixed $value[, bool $blnOverwrite = false ]) : mixed
Parameters
$property : string

Property name.

$value : mixed

Property value.

$blnOverwrite : bool = false

Optionally use this boolean to force an overwrite of previous property value.

Return values
mixed

The newly set value

setDynamicRemoveLabelMeta()

Set dynamic remove label specific meta data

public setDynamicRemoveLabelMeta(string $property, mixed $value[, bool $blnOverwrite = false ]) : mixed
Parameters
$property : string

Property name.

$value : mixed

Property value.

$blnOverwrite : bool = false

Optionally use this boolean to force an overwrite of previous property value.

Return values
mixed

The newly set value

setError()

Set a (custom) error message on this specific element

public setError(string $strError[, int $intDynamicPosition = 0 ]) : mixed

This is mostly used when doing custom server-side validation like validating a username existance. Example:

if ($objForm->isSubmitted() && $objForm->isValid()) {
    $objUserNameField = $objForm->getValidField("username");
    $strUserName = $objUserNameField->getValue();
    if (User::exists($strUserName)) {
        $objUserNameField->setError("User already exists.");
        $strOutput = $objForm->toHtml();
    } else {
        $strOutput = "Account created successfully with the following details:<br />";
        $strOutput .= $objForm->valuesAsHtml();
    }
}
Parameters
$strError : string

The error message

$intDynamicPosition : int = 0

Set the error message on a specific dynamic field with this index

setFieldMeta()

Set field specific meta data

public setFieldMeta(string $property, mixed $value[, bool $blnOverwrite = false ]) : mixed
Parameters
$property : string

Property name.

$value : mixed

Property value.

$blnOverwrite : bool = false

Optionally use this boolean to force an overwrite of previous property value.

Return values
mixed

The newly set value

setHint()

public setHint() : void

setHint(string $value) Overwrites the value of $__hint

setId()

public setId() : void

setId(string $value) Overwrites the value of $__id

setLabel()

public setLabel() : void

setLabel(string $value) Overwrites the value of $__label

setLabelMeta()

Set label specific meta data

public setLabelMeta(string $property, mixed $value[, bool $blnOverwrite = false ]) : mixed
Parameters
$property : string

Property name.

$value : mixed

Property value.

$blnOverwrite : bool = false

Optionally use this boolean to force an overwrite of previous property value.

Return values
mixed

The newly set value

setMeta()

Set meta property.

public setMeta(string $property, mixed $value[, bool $blnOverwrite = false ]) : array<string|int, mixed>
Parameters
$property : string

Property name.

$value : mixed

Property value.

$blnOverwrite : bool = false

Optionally use this boolean to force an overwrite of previous property value.

Return values
array<string|int, mixed>

setName()

public setName() : void

setName(string $value) Overwrites the value of $__name

setParent()

public setParent() : void

setParent(Base $value) Overwrites the value of $__parent

setRequiredStyle()

public setRequiredStyle() : void

setRequiredStyle(string $value) Overwrites the value of $__requiredstyle

setTip()

public setTip() : void

setTip(string $value) Overwrites the value of $__tip

setTipMeta()

Set tip specific meta data

public setTipMeta(string $property, mixed $value[, bool $blnOverwrite = false ]) : mixed
Parameters
$property : string

Property name.

$value : mixed

Property value.

$blnOverwrite : bool = false

Optionally use this boolean to force an overwrite of previous property value.

Return values
mixed

The newly set value

setType()

public setType() : void

setType(integer $value) Overwrites the value of $__type

setValidator()

public setValidator() : void

setValidator(FieldValidator $value) Overwrites the value of $__validator

toHtml()

Generate HTML

public toHtml([mixed $submitted = false ][, mixed $blnSimpleLayout = false ][, mixed $blnLabel = true ][, mixed $blnDisplayError = true ]) : string

See Element::toHtml()

Parameters
$submitted : mixed = false

Force if this field should behave like a submitted field or not (e.g. validate etc.)

$blnSimpleLayout : mixed = false

Force 'simple layout' output -- no labels and wrapping divs.

$blnLabel : mixed = true

Show label. Don't show if false.

$blnDisplayError : mixed = true
Tags
see
Element::toHtml()
Return values
string

toJS()

Generate Javascript

public toJS([mixed $intDynamicPosition = 0 ]) : string

See Element::toJS()

Parameters
$intDynamicPosition : mixed = 0

Dynamic position counter

Tags
see
Element::toJS()
Return values
string

        
On this page

Search results