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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObjectManager Module: Make All Text Lowercase


Go to End


3 Posts   1593 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

Forum Moderator, 4102 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.