xPDOMinValueValidationRule
Last updated Apr 12th, 2019 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn moreWhat Does the Rule Do?¶
This rule makes sure that the value of the field is at least X, where X is defined by the "value" attribute on the schema.
Using the Rule¶
First, our model:
<model package="test" baseClass="xPDOObject" platform="mysql"
defaultEngine="MyISAM" tablePrefix="test_">
<object class="myTest" table="test" extends="xPDOSimpleObject">
<field key="number" dbtype="int" precision="10"
phptype="integer" default="0" null="false" />
<validation>
<rule field="name"
name="myMinValRule"
type="xPDOValidationRule"
rule="xPDOMinValueValidationRule"
value="20"
message="The number must be at least 20."
/>
</validation>
</object>
</model>
From there, go ahead and generate the model from the XML schema. And now in a Snippet we'll call Test:
$output = '';
$modx->addPackage('test','/path/to/my/test/model/','test_');
$obj = $modx->newObject('myTest');
$obj->set('number',12);
$validator = $obj->getValidator();
if ($validator->validate() == false) {
$messages = $validator->getMessages();
foreach ($messages as $errorMsg) {
$output .= $errorMsg['message'];
}
}
This will display:
The number must be at least 20.
See Also¶
- xPDOForeignKeyConstraint
- xPDOMaxLengthValidationRule
- xPDOMaxValueValidationRule
- xPDOMinLengthValidationRule
- xPDOMinValueValidationRule
- xPDOObjectExistsValidationRule
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn more