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.

Customising the CMS /

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

[SOLVED] How get the CMS form of a DataObject "getCMSForm" method

Go to End

3 Posts   111 Views


Community Member, 2 Posts

18 July 2017 at 1:54am

Edited: 18/07/2017 1:57am

Hi all,

I am saving custom text fields in the CMS, what I mean by that is that where normally you'd have a DataObject with

private static $db = array(
'MyField' => 'Text'

And you then have
public function getCMSFields(){
TextField::create('MyField', 'Title of the field: ')
To add the fields to the form.

Well I am not using matching field names because I have custom save logic in place that saves the data some other way. So now I need to populate these textfields with data. Right now everytime you reload the CMS the fields are empty.

So what I'd like to to is

TextField::create('MyCustomNameThatDoesNotMatch', 'Title of the field: ', 'Initial data that the user is editing')

or (what I see as feasable): Some method that returns me the Form instance of the CMS Form so I can use loadDataFrom on it to populate the fields with the data.

I really hope this is possible so I can continue working :)

Thank you all for reading this!


Community Member, 344 Posts

21 July 2017 at 3:51am

Edited: 21/07/2017 4:09am

At a second glance, there are also extension hooks.

- GridFieldDetailForm_ItemRequest: $this->extend("updateItemEditForm", $form);

    - MyGridFieldDetailForm_ItemRequestExtension

class MyGridFieldDetailForm_ItemRequestExtension extends DataExtension {
	public function updateItemEditForm($form) {

- CMSMain: $this->extend('updateEditForm', $form);

    - MyCMSMainExtension

class MyCMSMainExtension extends DataExtension {
	public function updateEditForm($form) {


Community Member, 2 Posts

21 July 2017 at 4:25am

Thanks a lot! That is an excellent answer to what I asked. Fortunately I found out today that FormFields have a method called setValue() I really don't know how I missed that (for multiple hours!)
Anyway, thank you for your answer!