isDynamic()
isDynamic() : boolean
Check if the current field is a dynamic field.
Returns
boolean —True if dynamic, false if not.
Element Class
The base class for most form elements
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
string | $strType | Define the condition type. This can be either |
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 |
if Condition could not be set
If invalid arguments are supplied
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()
.
string | $strProperty | Condition type e.g. 'required', 'visibile' and 'enabled' |
Found condition or null if no condition is found.
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
string | $strProperty | Condition type e.g. 'required', 'visibile' and 'enabled' |
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.
string | $strProperty | Condition type e.g. |
\ValidFormBuilder\Element | $objContext |
setFieldMeta(string $property, mixed $value, boolean $blnOverwrite = false) : mixed
Set field specific meta data
string | $property | Property name. |
mixed | $value | Property value. |
boolean | $blnOverwrite | Optionally use this boolean to force an overwrite of previous property value. |
The newly set value
setLabelMeta(string $property, mixed $value, boolean $blnOverwrite = false) : mixed
Set label specific meta data
string | $property | Property name. |
mixed | $value | Property value. |
boolean | $blnOverwrite | Optionally use this boolean to force an overwrite of previous property value. |
The newly set value
setTipMeta(string $property, mixed $value, boolean $blnOverwrite = false) : mixed
Set tip specific meta data
string | $property | Property name. |
mixed | $value | Property value. |
boolean | $blnOverwrite | Optionally use this boolean to force an overwrite of previous property value. |
The newly set value
setDynamicLabelMeta(string $property, mixed $value, boolean $blnOverwrite = false) : mixed
Set dynamic label specific meta data
string | $property | Property name. |
mixed | $value | Property value. |
boolean | $blnOverwrite | Optionally use this boolean to force an overwrite of previous property value. |
The newly set value
setDynamicRemoveLabelMeta(string $property, mixed $value, boolean $blnOverwrite = false) : mixed
Set dynamic remove label specific meta data
string | $property | Property name. |
mixed | $value | Property value. |
boolean | $blnOverwrite | Optionally use this boolean to force an overwrite of previous property value. |
The newly set value
getLabelMeta(string $property = null, string $fallbackValue = "") : string
Get label meta property.
string | $property | Property to get from internal label meta array. |
string | $fallbackValue | Optional fallback value if requested property has no value |
Property value or empty string of none is set.
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()
integer | $intCount | The dynamic count |
The field name
setData(string $strKey = null, mixed $varValue = null) : boolean
Store data in the current object.
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!
string | $strKey | The key for this storage |
mixed | $varValue | The value to store |
True if set successful, false if not.
__construct(string $name, integer $type, string $label = "", array $validationRules = array(), array $errorHandlers = array(), array $meta = array())
Create new element
string | $name | Field name |
integer | $type | Field type |
string | $label | Field label |
array | $validationRules | Validation rules |
array | $errorHandlers | Error rules |
array | $meta | The meta array |
toHtml(boolean $submitted = false, boolean $blnSimpleLayout = false, boolean $blnLabel = true, boolean $blnDisplayErrors = true) : string
Generate HTML output
boolean | $submitted | Force if this field should behave like a submitted field or not (e.g. validate etc.) |
boolean | $blnSimpleLayout | Force 'simple layout' output -- no labels and wrapping divs. |
boolean | $blnLabel | Show label. Don't show if false. |
boolean | $blnDisplayErrors | Show errors (default true). Don't show errors if false. |
__toHtml(boolean $submitted = false, boolean $blnSimpleLayout = false, boolean $blnLabel = true, boolean $blnDisplayErrors = true, integer $intCount) : string
Generate HTML output for specific dynamic count
boolean | $submitted | |
boolean | $blnSimpleLayout | |
boolean | $blnLabel | |
boolean | $blnDisplayErrors | |
integer | $intCount |
setError(string $strError, integer $intDynamicPosition)
Set a (custom) error message on this specific element
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();
}
}
string | $strError | The error message |
integer | $intDynamicPosition | Set the error message on a specific dynamic field with this index |
isValid(null $intCount = null) : boolean
Validate the current field.
This is a wrapper method to call the Validator->validate() method. Although you could validate fields on a per-field basis with this method, this is mostly used internally. For instance, when \ValidFormBuilder\ValidForm::validate() is called, it loops trough it's elements collection and calls this method for each element it finds.
null | $intCount | Optional. If set, only the dynamic field with this index will be validated. |
True if field validates, false if not.
setDynamicCounter(\ValidFormBuilder\Element $objCounter)
Add a dynamic counter object
\ValidFormBuilder\Element | $objCounter |
__getValue(boolean $submitted = false, integer $intDynamicPosition) : string|null
Get the value of the field.
If the value is valid then it will return that value, otherwise the invalid value is returned.
boolean | $submitted | Indicate if the form is submitted. |
integer | $intDynamicPosition | The position of the field in a dynamic field setup. |
addField(mixed $name, mixed $type, mixed $validationRules = array() : \ValidFormBuilder\Element
, $errorHandlers = array(), $meta = array()) Adds another field to this field if this field is a container
mixed | $name | |
mixed | $type | |
mixed | $validationRules |