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.

Customising the CMS /

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

Validating DataObject in CMS

Go to End

4 Posts   3352 Views


Community Member, 83 Posts

5 August 2009 at 9:37am


i am still trying to find out how i can validate fields of a DataObject in CMS.
My first steps are using the function validate()

class News extends DataObject {

public function getCMSFields() {
public function validate() {
$valid = parent::validate();

if ((!$this->Title) || ($this->Title=="")) {
return $valid;

But with this I get the following:

[User Error] Uncaught ValidationException: Validation error writing a News object: Titel. Object not written.
POST ............/admin/EditForm/field/HomepageNews/AddForm

Line 715 in ........../sapphire/core/model/DataObject.php

So how do i have to catch the exception?


Community Member, 57 Posts

5 August 2009 at 11:58pm

Edited: 05/08/2009 11:59pm

So how do i have to catch the exception?

Spell Title right!



Community Member, 70 Posts

10 June 2010 at 10:03am


I'm very interressting by the response too :D ... I have the same problem !

I don't think it's the misspelling title because the first param of this error() method should be a message, a string (cf

Thanks for your help.


Community Member, 78 Posts

10 June 2010 at 2:43pm


If the data object has a method called getCMSValidator(), the CMS will call that to get a validator instance.

So for instance, you could do this:

function getCMSValidator() {
   return new RequiredFields(array("Field1", "Field2"));

RequiredFields is a built-in validator. You could equally well write a custom validator by extending Validator and putting in the right methods, and returning an instance of that.

Hope this helps