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.

Customising the CMS /

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

Adding new Textarea fields to CMS tab


Go to End


6 Posts   14411 Views

Avatar
Brady.Dyer

Community Member, 21 Posts

17 December 2008 at 2:30am

Edited: 17/12/2008 2:31am

Ok I've been trying to add a new field to a new page for about 4hours! its driving me crazy. I'm trying to add two new fields called Amy and Tash, which are text area fields, which can be edited in the CMS...

I've cut it down to just try and get ONE to work (the 'AboutAmy' field)

<?php
class AboutUsPage extends Page {
   static $db = array(
);
   static $has_one = array(
		   	'AboutAmy' => 'Text',
   );
	
function getCMSFields( $cms ) {
		$fields = parent::getCMSFields( $cms );
		$fields->addFieldToTab("Root.Content.Main", new TextareaField("AboutAmy", "About Amy"))
		return $fields;
	}
}
 
class AboutUsPage_Controller extends Page_Controller {
		}
		
?>

It shows up in the CMS fine... when you put something in the box, click save everything's fine - till you reload the page, then what ever change you made is NOT saved? Any ideas anyone?

Also - BIG UPS to the new SS site. so much nicer and easier to use, especially the new forum =)

Avatar
Brady.Dyer

Community Member, 21 Posts

17 December 2008 at 2:39am

Edited: 17/12/2008 2:39am

Well just fixed my own problem =) so thought I'd put up the fix here that I found here

When you put:

   static $has_one = array(
		   	'AmyInfo' => 'Text',
   );

It also adds a AmyInfoID into the table, so when you are adding this to the CMS you need to put:

$fields->addFieldToTab("Root.Content.Main", new TextField("AmyInfoID", "About Amy"));

Avatar
Brady.Dyer

Community Member, 21 Posts

17 December 2008 at 3:04am

Ok fixed that problem... but for some reason when rebuilding the CMS it is setting the field to be "int(11)"

Field AboutUsPage.AmyID: created as int(11) not null default '0'
Field AboutUsPage.TashID: created as int(11) not null default '0'

Any ideas how to change this to text?

Avatar
Brady.Dyer

Community Member, 21 Posts

17 December 2008 at 3:23am

are these two fields meant to be in has_one or db?

I tried this

<?php
 
class AboutUsPage extends Page {
   static $db = array(
			'Info_Amy' => 'Text',
		   	'Info_Tash' => 'Text',
);
   static $has_one = array(
	

   );
 	
	
	
	
function getCMSFields( $cms ) {
		$fields = parent::getCMSFields( $cms );
		
		$fields->addFieldToTab("Root.Content.Main", new TextareaField("Info_AmyID", "About Amy", "8", "3"));
		$fields->addFieldToTab("Root.Content.Main", new TextareaField("Info_TashID", "About Tash", "8", "3"));
		$fields->removeFieldFromTab("Root.Content.Main","Content");


			
			
			
		return $fields;
	}
	
}
 
class AboutUsPage_Controller extends Page_Controller {
	
		
		}
		
?>

and it now makes the fields 'mediumtext' not 'int(11)' - however when i put something into the CMS click save, it says it has saved, but when I open the page again - there is nothing in the fields in the CMS.

Avatar
Brady.Dyer

Community Member, 21 Posts

17 December 2008 at 3:26am

Ahhh shesh fixed my problem again :p haha.

When you move the fields into $db - it doesn't automatically add -ID to the end, so removed the ID's from the:
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Info_Amy", "About Amy", "8", "3"));
line and all works fine =)

here is the final code for those that care.

<?php
 
class AboutUsPage extends Page {
   static $db = array(
			'Info_Amy' => 'Text',
		   	'Info_Tash' => 'Text',
);
   static $has_one = array(
	

   );
 	
	
	
	
function getCMSFields( $cms ) {
		$fields = parent::getCMSFields( $cms );
		
		$fields->addFieldToTab("Root.Content.Main", new TextareaField("Info_Amy", "About Amy", "8", "3"));
		$fields->addFieldToTab("Root.Content.Main", new TextareaField("Info_Tash", "About Tash", "8", "3"));
		$fields->removeFieldFromTab("Root.Content.Main","Content");


			
			
			
		return $fields;
	}
	
}
 
class AboutUsPage_Controller extends Page_Controller {
	
		
		}
		
?>

Avatar
Martin Pales

Community Member, 19 Posts

17 December 2008 at 10:36am