xPDOValidator.addMessage
Last updated Apr 7th, 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
$301 per month—let's make that $500!
Learn morexPDOValidator::addMessage¶
Add a validation message to the stack.
Syntax¶
API Doc: http://api.modxcms.com/xpdo/om/xPDOValidator.html#addMessage
void addMessage (string $field, string $name, [mixed $message = null])
Example¶
Do our own validation, but still use the validator object.
$validator = $obj->getValidator();
if ($obj->get('name') == '') {
$validator->addMessage('name','emptyName','Please enter a valid name.');
}
$errors = $validator->getMessages();
foreach ($errors as $error) {
echo 'An error occurred with field "'.$error['name'].'": '.$error['message'];
}