Jump to main content Jump to doc navigation

xPDOValidator::getMessages

Get the validation messages generated by validate(), if any exist.

Each message is an array with the following keys:

  • field The name of the field that was validated against.
  • name The name of the validation rule.
  • message The error message returned.

Syntax

API Doc: http://api.modxcms.com/xpdo/om/xPDOValidator.html#getMessages

array getMessages ()

Example

Check to see if any validation errors occur. If so, return the errors and print out to the browser.

$validator = $obj->getValidator();
if ($validator->validate() == false) {
   $errorMessages = $validator->getMessages();
   foreach ($errorMessages as $message) {
       echo 'An error occurred on field "'.$message['field'].'": '.$message['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
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

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

Learn more