Jump to main content Jump to doc navigation

xPDOValidator::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'];
}

See Also

  1. xPDOValidator.addMessage
  2. xPDOValidator.getMessages
  3. xPDOValidator.hasMessages
  4. xPDOValidator.validate