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();
}
}
Parameters
string
$strError
The error message
integer
$intDynamicPosition
Set the error message on a specific dynamic field with this index
toJS()
toJS(integer $intDynamicPosition) : string
Render javascript
Should be extended by child classes.
Parameters
integer
$intDynamicPosition
Dynamic position counter
Returns
string
getRandomId()
getRandomId(string $name) : string
Generate a random ID for a given field name to prevent having two fields with the same name
Parameters
string
$name
Field name
Returns
string
isValid()
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.
Parameters
null
$intCount
Optional. If set, only the dynamic field with this index will be validated.
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.
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!