ValidForm Builder API Documentation

Condition extends ClassDynamic
in package

Condition class

A condition object is a set of one or more comparisons. Don't use the Condition object as a standalone, rather use the element's Base::addCondition() method.

Example; Basic yes-no condition

$objCheck = $objForm->addField("yesno", "Yes or No", ValidForm::VFORM_RADIO_LIST);
$objYes = $objCheck->addField("Yes", "yes");
$objCheck->addField("No", "no");

$objText = $objForm->addField(
    "textfield",
    "Text here",
    ValidForm::VFORM_TEXT,
    array("required" => "true"),
    array("required" => "This field is required"),
    array("fielddisabled" => "disabled")
);
$objText->addCondition("enabled", true, array(
	new Comparison($objYes, ValidForm::VFORM_COMPARISON_EQUAL, "yes")
));

Example 2; Hide field when other field has predefined value

$objFirstName = $objForm->addField('firstname', 'First name', ValidForm::VFORM_STRING);
$objLastName = $objForm->addField('lastname', 'Last name', ValidForm::VFORM_STRING);
$objLastName->addCondition(
    'visible', // Last name will become
    false, // 'not visible' (visible -> false)
    array(
        // When field $objFirstName 'is equal to' Robin
        new \ValidFormBuilder\Comparison($objFirstName, ValidForm::VFORM_COMPARISON_EQUAL, 'Robin')
    )
);

Example 3; Trigger condition with comparison that doesn't need a value

$objFirstName = $objForm->addField('firstname', 'First name', ValidForm::VFORM_STRING);
$objLastName = $objForm->addField('lastname', 'Last name', ValidForm::VFORM_STRING);
$objFirstName->addCondition(
    'enabled', // First Name will be
    false, // 'disabled' (enabled -> false)
    array(
        // When field $objLastName 'is not empty'
        // (note that we cal leave out the third 'value' parameter in this case)
        new \ValidFormBuilder\Comparison($objLastName, ValidForm::VFORM_COMPARISON_NOT_EMPTY)
    )
);
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 Condition
__get()  : mixed
Magic getter method
__set()  : mixed
Magic setter method
addComparison()  : mixed
Add new comparison to Condition
getComparisons()  : array<string|int, mixed>
Get comparisons collection
getComparisonType()  : string
Get comparison type
getProperty()  : string
Get Property
getSubject()  : Base
Get subject value
getValue()  : bool
Get value
isMet()  : bool
Verify if the condition is met
jsonSerialize()  : array<string|int, mixed>
toJson method creates an array representation of the current condition object and all of it's comparions.

Methods

__call()

Magic caller method

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

__construct()

Create new Condition

public __construct(Base $objField, string $strProperty[, bool $blnValue = null ][, string $strComparisonType = ValidForm::VFORM_MATCH_ANY ]) : mixed
Parameters
$objField : Base

The target field to apply this condition on

$strProperty : string

The property to trigger on the subject; enabled, visible or required

$blnValue : bool = null

The boolean to set the property with. E.g. when property is required and value is false, the field will become optional when the condition is met.

$strComparisonType : string = ValidForm::VFORM_MATCH_ANY

The comparison type

Tags
throws
InvalidArgumentException

If $objField is no object or $strProperty is no predefined property.

__get()

Magic getter method

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

__set()

Magic setter method

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

addComparison()

Add new comparison to Condition

public addComparison(Comparison|array<string|int, mixed> $varComparison) : mixed
Parameters
$varComparison : Comparison|array<string|int, mixed>

Comparison array or Comparison object

Tags
throws
Exception

if Reflection couldn't initialize new Comparison object

throws
InvalidArgumentException

if no valid Comparison data is supplied

getComparisons()

Get comparisons collection

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

getComparisonType()

Get comparison type

public getComparisonType() : string
Return values
string

getProperty()

Get Property

public getProperty() : string
Return values
string

getSubject()

Get subject value

public getSubject() : Base
Return values
Base

Subject element

getValue()

Get value

public getValue() : bool
Return values
bool

isMet()

Verify if the condition is met

public isMet([int $intDynamicPosition = 0 ]) : bool
Parameters
$intDynamicPosition : int = 0

Dynamic position of the field to verify

Tags
throws
Exception
Return values
bool

True if it is met, false if not

jsonSerialize()

toJson method creates an array representation of the current condition object and all of it's comparions.

public jsonSerialize([int|null $intDynamicPosition = null ]) : array<string|int, mixed>

In the future this class should extend the JsonSerializable interface (http://php.net/manual/en/class.jsonserializable.php). Since this is only supported in PHP >= 5.4, we now use our own implementation.

Parameters
$intDynamicPosition : int|null = null
Return values
array<string|int, mixed>

An array representation of this object and it's comparisons.


        
On this page

Search results