\ValidFormBuilderCondition

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 \ValidFormBuilder\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)
    )
);

Summary

Methods
Properties
Constants
__construct()
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

__construct()

__construct(\ValidFormBuilder\Base  $objField, string  $strProperty, boolean  $blnValue = null, string  $strComparisonType = \ValidFormBuilder\ValidForm::VFORM_MATCH_ANY) 

Create new Condition

Parameters

\ValidFormBuilder\Base $objField

The target field to apply this condition on

string $strProperty

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

boolean $blnValue

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.

string $strComparisonType

The comparison type

Throws

\InvalidArgumentException

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