We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37286
    • 160 Posts
    I have a manager page that has to go through validation, and I have the front end of the site that has to run through similar validation. While the two are not exactly the same, it would be nice to do the overlapping validation in one place. I have done some simple things, like the below code, but what if I had a field that cannot be blank, or make sure a date range doesn't overlap another date range? How would I read the error from the object class to the processor class so I could display the error?

    class MyObject extends xPDOObject {
        public function save($cacheFlag= null) {
            if ($this->isNew()) {
                $this->set('createdon','NOW');
            } else {
                $this->set('editedon','NOW');
            }
            $saved= parent :: save($cacheFlag);
            return $saved;
        }
    }
      • 22303 MODX Staff
      • 10,725 Posts
      You can define validation rules in your model and/or in your code using the xPDOValidator API. You can also execute that validation separately or have it run automatically on save.

      See xPDO Object Validation for more information.