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

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

  • modmore
  • modmore
  • Jens Wittmann – Gestaltung & Entwicklung
  • Raffy
  • eydolan
  • Digital Penguin
  • Fabian Christen
  • Dannevang Digital
  • deJaya
  • Sepia River Studios
  • Following Sea
  • Anton Tarasov
  • Lefthandmedia
  • Nick Clark
  • Chris Fickling
  • Murray Wood
  • YJ
  • CrewMark
  • Richard

Budget

$305 per month—let's make that $500!

Learn more