Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager Module: Make All Text Lowercase

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: 1038 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    DataObjectManager Module: Make All Text Lowercase Link to this post

    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')
          );
       }
    }
    ?>

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: DataObjectManager Module: Make All Text Lowercase Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager Module: Make All Text Lowercase Link to this post

    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.

    1038 Views
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.