7921 Posts in 1359 Topics by 933 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 838 Views |
-
DataObjectManager Module: Make All Text Lowercase

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')
);
}
}
?> -
Re: DataObjectManager Module: Make All Text Lowercase

18 August 2010 at 3:25pm
function onBeforeWrite() {
parent::onBeforeWrite();
$this->Section = strtoupper($this->Section);
} -
Re: DataObjectManager Module: Make All Text Lowercase

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.
| 838 Views | ||
|
Page:
1
|
Go to Top |


