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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObjectManager Module: Make All Text Lowercase


Reply


3 Posts   1055 Views

Avatar
DeklinKelly

Community Member, 197 Posts

17 August 2010 at 5:38am

When items are added with the DataObjectManager Module, I want them to be saved such that all uppercase letters are converted to lowercase letters.

Here is my code:

<?php

class SectionItem extends DataObject
{
   static $db = array (
      'Section' => 'Text'
   );

   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Section')
      );
   }
}
?>

Avatar
Bambii7

Community Member, 254 Posts

18 August 2010 at 3:25pm

function onBeforeWrite() {
parent::onBeforeWrite();
$this->Section = strtoupper($this->Section);
}

Avatar
UncleCheese

4085 Posts

18 August 2010 at 4:03pm

Are you sure about that, Bambii? $this->Section refers to the current value. Since the record hasn't been written at this point, the object is still storing the old value. You need to get the value that was passed through the form. Something like $_REQUEST['Section'], for instance, but there has to be a cleaner way.