Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Adding new Textarea fields to CMS tab

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

Page: 1
Go to End
Author Topic: 5766 Views
  • Brady.Dyer
    Avatar
    Community Member
    21 Posts

    Adding new Textarea fields to CMS tab Link to this post

    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 =)

  • Brady.Dyer
    Avatar
    Community Member
    21 Posts

    Re: Adding new Textarea fields to CMS tab Link to this post

    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"));

  • Brady.Dyer
    Avatar
    Community Member
    21 Posts

    Re: Adding new Textarea fields to CMS tab Link to this post

    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?

  • Brady.Dyer
    Avatar
    Community Member
    21 Posts

    Re: Adding new Textarea fields to CMS tab Link to this post

    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.

  • Brady.Dyer
    Avatar
    Community Member
    21 Posts

    Re: Adding new Textarea fields to CMS tab Link to this post

    Ahhh shesh fixed my problem again 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 {
       
          
          }
          
    ?>

  • Martin Pales
    Avatar
    Community Member
    19 Posts
    5766 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.