Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Validation/RequiredFields & DataObjectManger Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1823 Views
  • Diomedes22
    Community Member
    1 Post

    Validation/RequiredFields & DataObjectManger Module Link to this post

    Dear Reader,

    Let me first start with the fact that I am very new to SilverStripe. Before getting myself into all kind of troubles I started of reading the Tutorials, and heard about this Module for SilverStripe by a Colleague.

    It all seemed to work fine, until i wondered how to do validating with the DataObjectManager_Popup Form. Some strange things seem to happen over there! We noticed some other people asked for a solution, but from my point of view there wasn't one yet.

    First post i found: link 1
    Second post i found: link 2

    We worked on figuring how to make it work, and voila:

    class Person extends DataObject {
       static $db = array(
          "FirstName" => "Varchar(40)",
          "LastName" => "Varchar(40)",
          "Gender" => "Enum('Man, Vrouw','Man')",
          "DateOfBirth" => "Date",
          "Description" => "HTMLText"

       static $has_one = array('PersonHolder' => 'PersonHolder');
       public function getCMSFields_forPopup(){
          $fieldSet = new FieldSet(
             new TextField('FirstName', 'Voornaam','','40'),
             new TextField('LastName', 'Achternaam', '','40'),
             new DropdownField('Gender', 'Geslacht', array('Man', 'Vrouw')),
             new CalendarDateField('DateOfBirth','Geboorte Datum'),
             new HtmlEditorField('Description','Beschrijving')      
          return $fieldSet;


    class PersonHolder extends Page {

       static $db = array();
       static $has_many = array(
          "Persons" => "Person"
       public function getCMSFields(){
          $oDOM = new DataObjectManager(
                'FirstName' => 'Voornaam',
                'LastName' => 'Achternaam',
                'Gender' => 'Geslacht',
                'DateOfBirth' => 'Geboorte Datum',
                'Description' => 'Beschrijving'
          $oDOM->popupClass = 'PersonDataObjectManager_Popup';

          $fields = parent::getCMSFields();
          return $fields;

    class PersonHolder_Controller extends Page_Controller {

    class PersonDataObjectManager_Popup extends DataObjectManager_Popup {
       function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
          parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
          $oVal = new RequiredFields(array('FirstName', 'LastName'));
          $this->validator = $oVal;

  • splatEric
    Community Member
    15 Posts

    Re: Validation/RequiredFields & DataObjectManger Module Link to this post

    This was really helpful ... I was wondering if you found a way of having the popup maintain the data that was entered on the form when it was invalid?



  • Stef87
    Community Member
    66 Posts

    Re: Validation/RequiredFields & DataObjectManger Module Link to this post

    Hi Mike,

    Did you ever find a solution to this? I am having trouble finding a way to retain the data and it is causing major headaches.



Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.