MultiField
extends Base
in package
Create a Multifield element
Multifield elements allow you to combine multiple fields horizontally with one label. For example, create a first name + last name field with label "Full name"
$objMulti = $objForm->addMultifield("Full name");
// Note: when using addField on a multifield, we don't set a label!
$objMulti->addField(
"first-name",
ValidForm::VFORM_STRING,
array(),
array(),
// Keep it short, this is just a first name field
array("style" => "width: 50px")
);
$objMulti->addField("last-name", ValidForm::VFORM_STRING);
You can also combine select elements to create a date picker:
$objMulti = $objForm->addMultiField("Birthdate");
$objMulti->addField(
"year",
ValidForm::VFORM_SELECT_LIST,
array(),
array(),
array(
"start" => 1920,
"end" => 2014,
// 'fieldstyle' gets applied on the <select>
// regular 'style' applies on the wrapping <div>
"fieldstyle" => "width: 75px"
)
);
$objMulti->addField(
"month",
ValidForm::VFORM_SELECT_LIST,
array(),
array(),
array(
"start" => 01,
"end" => 12,
"fieldstyle" => "width: 75px"
)
);
$objMulti->addField(
"day",
ValidForm::VFORM_SELECT_LIST,
array(),
array(),
array(
"start" => 1,
"end" => 31,
"fieldstyle" => "width: 75px"
)
);
Tags
Table of Contents
Methods
- __call() : mixed
- Magic caller method
- __construct() : mixed
- Create a new MultiField instance
- __get() : mixed
- Magic getter method
- __set() : mixed
- Magic setter method
- __toHtml() : string
- See {@see \ValidFormBuilder\Base::__toHtml()}
- addCondition() : mixed
- Add a new condition to the current field
- addField() : Element
- Add a field to the MultiField collection.
- addText() : StaticText
- Add text to the multifield.
- 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.
- 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 dynamic count of this multifield
- 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.
- getFields() : Collection
- Get Fields collection
- getId() : string
- Get MultiField ID
- 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
- 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.
- getTipMeta() : array<string|int, mixed>
- getType() : int
- Get field type - placeholder to overwrite default logic
- getValue() : bool
- Get value - placeholder
- 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.
- hasContent() : bool
- Loop through all child fields and check their values. If one value is not empty, the MultiField has content.
- hasFields() : bool
- Check if MultiField has internal fields in it's collection
- isDynamic() : bool
- Check if multifield is dynamic
- isValid() : bool
- Validate internal fields
- 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.
- setDynamicLabelMeta() : mixed
- Set dynamic label specific meta data
- setDynamicRemoveLabelMeta() : mixed
- Set dynamic remove label specific meta data
- setFieldMeta() : mixed
- Set field specific meta data
- 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
- setTipMeta() : mixed
- Set tip specific meta data
- toHtml() : string
- See {@see \ValidFormBuilder\Base::toHtml()}
- toJS() : string
- Generate Javascript See {@\ValidFormBuilder\Base::toJS()}
Methods
__call()
Magic caller method
public
__call(string $method, mixed $values) : mixed
Parameters
- $method : string
- $values : mixed
Tags
__construct()
Create a new MultiField instance
public
__construct(string $label[, array<string|int, mixed> $meta = array() ][, mixed $name = null ]) : mixed
See MultiField for examples near the top of this page
Parameters
- $label : string
-
The multifield's label
- $meta : array<string|int, mixed> = array()
-
The meta array
- $name : mixed = null
__get()
Magic getter method
public
__get(string $property) : mixed
Parameters
- $property : string
Tags
__set()
Magic setter method
public
__set(string $property, mixed $value) : mixed
Parameters
- $property : string
- $value : mixed
Tags
__toHtml()
See {@see \ValidFormBuilder\Base::__toHtml()}
public
__toHtml([bool $submitted = false ][, bool $blnSimpleLayout = false ][, bool $blnLabel = true ][, bool $blnDisplayError = true ][, int $intCount = 0 ]) : string
Parameters
- $submitted : bool = false
- $blnSimpleLayout : bool = false
- $blnLabel : bool = true
- $blnDisplayError : bool = true
- $intCount : int = 0
Return values
string —Generated HTML
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,visibileorenabled - $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_ANYorValidForm::VFORM_MATCH_ALL. WithVFORM_MATCH_ANY, as soon as one of the comparisons validates the condition, the condition is enforced. WithValidForm::VFORM_MATCH_ALL, all of the comparisons must validate before the condition will be enforced.
Tags
addField()
Add a field to the MultiField collection.
public
addField(string $name, int $type[, array<string|int, mixed> $validationRules = array() ][, array<string|int, mixed> $errorHandlers = array() ][, array<string|int, mixed> $meta = array() ]) : Element
Same as ValidForm::addField() with the only difference that the MultiField::addField()
does not take a field label since that's already set when initialising the MultiField.
Parameters
- $name : string
-
Field name
- $type : int
-
Field type
- $validationRules : array<string|int, mixed> = array()
-
Validation rules array
- $errorHandlers : array<string|int, mixed> = array()
-
Error handling array
- $meta : array<string|int, mixed> = array()
-
The meta array
Return values
ElementaddText()
Add text to the multifield.
public
addText(string $strText[, array<string|int, mixed> $meta = array() ]) : StaticText
Same as ValidForm::addText()
Parameters
- $strText : string
-
The text to add (can be HTML as well)
- $meta : array<string|int, mixed> = array()
-
The meta array
Return values
StaticTextgetCondition()
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,visibileandenabled - $objContext : Element = null
Return values
Condition|nullgetConditions()
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 $key = null ]) : mixed
See Base::getData() for a full description
Parameters
- $key : string = null
-
The key of the data attribute to return
Return values
mixed —If a key is provided, return it's value. If no key provided, return the whole data array. If anything is not set or incorrect, return false.
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 dynamic count of this multifield
public
getDynamicCount() : int
Return values
intgetDynamicLabelMate()
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
getFields()
Get Fields collection
public
getFields() : Collection
Return values
CollectiongetId()
Get MultiField ID
public
getId() : string
Return values
stringgetLabel()
public
getLabel() : string
getLabel() Returns the value of $__label
Return values
stringgetLabelMeta()
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|ConditiongetName()
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
BasegetRequiredStyle()
public
getRequiredStyle() : string
getRequiredStyle() Returns the value of $__requiredstyle
Return values
stringgetReservedFieldMeta()
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
getTipMeta()
public
getTipMeta() : array<string|int, mixed>
getTipMeta() Returns the value of $__tipmeta
Return values
array<string|int, mixed>getType()
Get field type - placeholder to overwrite default logic
public
getType() : int
Return values
intgetValue()
Get value - placeholder
public
getValue() : bool
Return values
boolhasCondition()
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,visibileandenabled
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.
hasContent()
Loop through all child fields and check their values. If one value is not empty, the MultiField has content.
public
hasContent([int $intCount = 0 ]) : bool
Parameters
- $intCount : int = 0
-
The current dynamic count.
Return values
bool —True if multifield has content, false if not.
hasFields()
Check if MultiField has internal fields in it's collection
public
hasFields() : bool
Return values
boolisDynamic()
Check if multifield is dynamic
public
isDynamic() : bool
Return values
boolisValid()
Validate internal fields
public
isValid() : bool
Return values
boolsetConditionalMeta()
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
See Base::setData() for a full description
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.
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
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
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
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
toHtml()
See {@see \ValidFormBuilder\Base::toHtml()}
public
toHtml([bool $submitted = false ][, bool $blnSimpleLayout = false ][, bool $blnLabel = true ][, bool $blnDisplayError = true ]) : string
Parameters
- $submitted : bool = false
- $blnSimpleLayout : bool = false
- $blnLabel : bool = true
- $blnDisplayError : bool = true
Return values
string —Generated HTML
toJS()
Generate Javascript See {@\ValidFormBuilder\Base::toJS()}
public
toJS([mixed $intDynamicPosition = 0 ]) : string
Parameters
- $intDynamicPosition : mixed = 0
-
Dynamic position