Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

CMS DataObject validation

Go to End



Community Member, 23 Posts

5 March 2012 at 3:59pm

Edited: 05/03/2012 10:44pm


I know this is an old one ...

I have started fighting with DataObjects and input validation in the CMS backend. Specifically, I have a DataObjectManager (DOM) which manages DataObjects. When the adminstrator adds a new DataObject via the DOM a popup form appears, they enter data, then hit save. Nothing special there. The sort of thing I need to do is reject the DataObject on save if there are any problems (i.e. empty fields).

This seems like obvious functionality and I can't be the first one to need a robust solution.

The best I have come up with so far is overriding DataObject::validate() and returning a ValidationResult object i.e. return ValidationResult(false, "you stuffed up");. That works, but I lose all the form fields, requiring the administrator to re-add them. They wont be happy with that (but they may have to be).

I have seen this problem mentioned once or twice but with no obvious solution. Does it require some modification to the 2.4.6 framework, or am I missing something?

I looked at overriding DataObject::getCMSValidtor() with my own RequiredFields validator (as I found in another post) but found that getCMSValidator() is not called by the framework - nor is it in the DataObject API.

How are the experts out there solving this problem?

Thanks very much,