\ValidFormBuilderMultiField

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"
    )
);

Summary

Methods
Properties
Constants
isDynamic()
addCondition()
getConditions()
getCondition()
getMetCondition()
hasCondition()
hasConditions()
getConditionRecursive()
getDynamicButtonMeta()
setConditionalMeta()
setMeta()
setFieldMeta()
getFieldMeta()
setLabelMeta()
setTipMeta()
setDynamicLabelMeta()
setDynamicRemoveLabelMeta()
getMeta()
getLabelMeta()
getName()
getDynamicName()
getShortLabel()
toJS()
setData()
getData()
__get()
__set()
__call()
__construct()
addField()
addText()
toHtml()
__toHtml()
isValid()
getDynamicCount()
getFields()
getValue()
getId()
getType()
hasContent()
hasFields()
getLabel()
setLabel()
getRequiredStyle()
setRequiredStyle()
getId()
setId()
setName()
getParent()
setParent()
setConditions()
getTipMeta()
getDynamicLabelMate()
getDynamicRemoveLabelMate()
getMagicMeta()
getMagicReservedMeta()
getReservedFieldMeta()
getReservedLabelMeta()
getReservedMeta()
hasFields()
getFields()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

isDynamic()

isDynamic() : boolean

Check if multifield is dynamic

Returns

boolean

addCondition()

addCondition(string  $strType, boolean  $blnValue, array  $arrComparisons, string  $intComparisonType = \ValidFormBuilder\ValidForm::VFORM_MATCH_ANY) 

Add a new condition to the current field

For examples, check \ValidFormBuilder\Condition

Parameters

string $strType

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

boolean $blnValue

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

array $arrComparisons

An array of Comparison objects

string $intComparisonType

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.

Throws

\Exception

if Condition could not be set

\InvalidArgumentException

If invalid arguments are supplied

getConditions()

getConditions() : array

Get the conditions collection

Returns

array

getCondition()

getCondition(string  $strProperty) : \ValidFormBuilder\Condition|null

Get element's Condition object

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

Parameters

string $strProperty

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

Returns

\ValidFormBuilder\Condition|null —

Found condition or null if no condition is found.

getMetCondition()

getMetCondition(string  $strProperty) : null|\ValidFormBuilder\Condition

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

Parameters

string $strProperty

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

Returns

null|\ValidFormBuilder\Condition

hasCondition()

hasCondition(string  $strProperty) : boolean

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

Parameters

string $strProperty

Condition type e.g. required, visibile and enabled

Returns

boolean —

True if element has condition object set, false if not

hasConditions()

hasConditions() : boolean

Check if the current object contains any conditions at all.

Returns

boolean —

True if it contains conditions, false if not.

getConditionRecursive()

getConditionRecursive(string  $strProperty, \ValidFormBuilder\Element  $objContext = null) : \ValidFormBuilder\Condition|null

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

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

Parameters

string $strProperty

Condition type e.g. required, visibile and enabled

\ValidFormBuilder\Element $objContext

Returns

\ValidFormBuilder\Condition|null

getDynamicButtonMeta()

getDynamicButtonMeta() 

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

setConditionalMeta()

setConditionalMeta() 

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

setMeta()

setMeta(string  $property, mixed  $value, boolean  $blnOverwrite = false) : array

Set meta property.

Parameters

string $property

Property name.

mixed $value

Property value.

boolean $blnOverwrite

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

Returns

array

setFieldMeta()

setFieldMeta(string  $property, mixed  $value, boolean  $blnOverwrite = false) : mixed

Set field specific meta data

Parameters

string $property

Property name.

mixed $value

Property value.

boolean $blnOverwrite

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

Returns

mixed —

The newly set value

getFieldMeta()

getFieldMeta(string  $property = null, string  $fallbackValue = "") : mixed

Get field meta property.

Parameters

string $property

Property to get from internal field meta array.

string $fallbackValue

Optional fallback value if no value is found for requested property

Returns

mixed

setLabelMeta()

setLabelMeta(string  $property, mixed  $value, boolean  $blnOverwrite = false) : mixed

Set label specific meta data

Parameters

string $property

Property name.

mixed $value

Property value.

boolean $blnOverwrite

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

Returns

mixed —

The newly set value

setTipMeta()

setTipMeta(string  $property, mixed  $value, boolean  $blnOverwrite = false) : mixed

Set tip specific meta data

Parameters

string $property

Property name.

mixed $value

Property value.

boolean $blnOverwrite

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

Returns

mixed —

The newly set value

setDynamicLabelMeta()

setDynamicLabelMeta(string  $property, mixed  $value, boolean  $blnOverwrite = false) : mixed

Set dynamic label specific meta data

Parameters

string $property

Property name.

mixed $value

Property value.

boolean $blnOverwrite

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

Returns

mixed —

The newly set value

setDynamicRemoveLabelMeta()

setDynamicRemoveLabelMeta(string  $property, mixed  $value, boolean  $blnOverwrite = false) : mixed

Set dynamic remove label specific meta data

Parameters

string $property

Property name.

mixed $value

Property value.

boolean $blnOverwrite

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

Returns

mixed —

The newly set value

getMeta()

getMeta(string  $property = null, string  $fallbackValue = "") : mixed

Get meta property.

Parameters

string $property

Property to get from internal meta array.

string $fallbackValue

Optional fallback value if requested property has no value

Returns

mixed

getLabelMeta()

getLabelMeta(string  $property = null, string  $fallbackValue = "") : string

Get label meta property.

Parameters

string $property

Property to get from internal label meta array.

string $fallbackValue

Optional fallback value if requested property has no value

Returns

string —

Property value or empty string of none is set.

getName()

getName() : string

Return the (original) name of the current field.

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

Returns

string —

The original field name

getDynamicName()

getDynamicName(integer  $intCount) : string

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

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

Parameters

integer $intCount

The dynamic count

Returns

string —

The field name

getShortLabel()

getShortLabel() : string

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

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

Returns

string —

The short or regular element label

toJS()

toJS(integer  $intDynamicPosition) : string

Generate Javascript See {@\ValidFormBuilder\Base::toJS()}

Should be extended by child classes.

Parameters

integer $intDynamicPosition

Dynamic position

Returns

string

setData()

setData(string  $strKey = null, mixed  $varValue = null) : boolean

Store data in the current object.

See \ValidFormBuilder\Base::setData() for a full description

Parameters

string $strKey

The key for this storage

mixed $varValue

The value to store

Returns

boolean —

True if set successful, false if not.

getData()

getData(string  $key = null) : mixed

Get a value from the internal data array.

See \ValidFormBuilder\Base::getData() for a full description

Parameters

string $key

The key of the data attribute to return

Returns

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.

__get()

__get(string  $property) 

Magic getter method

Parameters

string $property

Throws

\BadMethodCallException

__set()

__set(string  $property, mixed  $value) 

Magic setter method

Parameters

string $property
mixed $value

Throws

\BadMethodCallException

__call()

__call(string  $method, mixed  $values) 

Magic caller method

Parameters

string $method
mixed $values

Throws

\BadMethodCallException

__construct()

__construct(string  $label, array  $meta = array(),   $name = null) 

Create a new MultiField instance

See top of this page for examples

Parameters

string $label

The multifield's label

array $meta

The meta array

$name

addField()

addField(string  $name, integer  $type, array  $validationRules = array(), array  $errorHandlers = array(), array  $meta = array()) : \ValidFormBuilder\Element

Add a field to the MultiField collection.

Same as \ValidFormBuilder\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

string $name

Field name

integer $type

Field type

array $validationRules

Validation rules array

array $errorHandlers

Error handling array

array $meta

The meta array

Returns

\ValidFormBuilder\Element

addText()

addText(string  $strText, array  $meta = array()) : \ValidFormBuilder\StaticText

Add text to the multifield.

Same as \ValidFormBuilder\ValidForm::addText()

Parameters

string $strText

The text to add (can be HTML as well)

array $meta

The meta array

Returns

\ValidFormBuilder\StaticText

toHtml()

toHtml(boolean  $submitted = false, boolean  $blnSimpleLayout = false, boolean  $blnLabel = true, boolean  $blnDisplayError = true) : string

See {@link \ValidFormBuilder\Base::toHtml()}

Parameters

boolean $submitted
boolean $blnSimpleLayout
boolean $blnLabel
boolean $blnDisplayError

Returns

string —

Generated HTML

__toHtml()

__toHtml(boolean  $submitted = false, boolean  $blnSimpleLayout = false, boolean  $blnLabel = true, boolean  $blnDisplayError = true, integer  $intCount) : string

See {@link \ValidFormBuilder\Base::__toHtml()}

Parameters

boolean $submitted
boolean $blnSimpleLayout
boolean $blnLabel
boolean $blnDisplayError
integer $intCount

Returns

string —

Generated HTML

isValid()

isValid() : boolean

Validate internal fields

Returns

boolean

getDynamicCount()

getDynamicCount() : integer

Get the dynamic count of this multifield

Returns

integer

getValue()

getValue() : boolean

Get value - placeholder

Returns

boolean

getId()

getId() : string

Get MultiField ID

Returns

string

getType()

getType() : integer

Get field type - placeholder to overwrite default logic

Returns

integer

hasContent()

hasContent(integer  $intCount) : boolean

Loop through all child fields and check their values. If one value is not empty, the MultiField has content.

Parameters

integer $intCount

The current dynamic count.

Returns

boolean —

True if multifield has content, false if not.

hasFields()

hasFields() : boolean

Check if MultiField has internal fields in it's collection

Returns

boolean

getLabel()

getLabel() : string

Returns the value of $__label

Returns

string

setLabel()

setLabel(string  $value) : void

Overwrites the value of $__label

Parameters

string $value

getRequiredStyle()

getRequiredStyle() : string

Returns the value of $__requiredstyle

Returns

string

setRequiredStyle()

setRequiredStyle(string  $value) : void

Overwrites the value of $__requiredstyle

Parameters

string $value

getId()

getId() : string

Returns the value of $__id

Returns

string

setId()

setId(string  $value) : void

Overwrites the value of $__id

Parameters

string $value

setName()

setName(string  $value) : void

Overwrites the value of $__name

Parameters

string $value

getParent()

getParent() : \ValidFormBuilder\Base

Returns the value of $__parent

Returns

\ValidFormBuilder\Base

setParent()

setParent(\Base  $value) : void

Overwrites the value of $__parent

Parameters

\Base $value

setConditions()

setConditions(array  $value) : void

Overwrites the value of $__conditions

Parameters

array $value

getTipMeta()

getTipMeta() : array

Returns the value of $__tipmeta

Returns

array

getDynamicLabelMate()

getDynamicLabelMate() : array

Returns the value of $__dynamiclabelmeta

Returns

array

getDynamicRemoveLabelMate()

getDynamicRemoveLabelMate() : array

Returns the value of $__dynamicremovelabelmeta

Returns

array

getMagicMeta()

getMagicMeta() : array

Returns the value of $__magicmeta

Returns

array

getMagicReservedMeta()

getMagicReservedMeta() : array

Returns the value of $__magicreservedmeta

Returns

array

getReservedFieldMeta()

getReservedFieldMeta() : array

Returns the value of $__reservedfieldmeta

Returns

array

getReservedLabelMeta()

getReservedLabelMeta() : array

Returns the value of $__reservedlabelmeta

Returns

array

getReservedMeta()

getReservedMeta() : array

Returns the value of $__reservedmeta

Returns

array

hasFields()

hasFields() : boolean

Returns if this element has any child fields

Returns

boolean

getFields()

getFields() : \ValidFormBuilder\Collection

Returns a collection of child fields

Returns

\ValidFormBuilder\Collection