Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Data won't save to in the fields I created [Solved]

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

Page: 1
Go to End
Author Topic: 1238 Views
  • maryfran
    Avatar
    Community Member
    12 Posts

    Data won't save to in the fields I created [Solved] Link to this post

    I created some custom fields for a promo slider on a website home page. No data will save to these fields (well, they save to the image ones but not to the text or HTMLText ones. My code is below:

    class HomePage extends Page {
    static $db = array(
    );
    static $has_one = array(
    'Promo1' => 'Image',
        'Promo2' => 'Image',
        'Promo3' => 'Image',
        'PromoText1' => 'HTMLText',
        'PromoText2' => 'HTMLText',
        'PromoText3' => 'HTMLText',
        'PromoName1' => 'Text',
        'PromoName2' => 'Text',
        'PromoName3' => 'Text',
    );
       
    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->removeFieldFromTab("Root.Content.Main","Content");
       $fields->addFieldToTab('Root.Content.Main', new TextField('PromoName1'));
       $fields->addFieldToTab('Root.Content.Promos', new HtmlEditorField($name = "PromoText1",$title = "Promo Text 1"));
       $fields->addFieldToTab('Root.Content.Promos', new ImageField('Promo1'));
       $fields->addFieldToTab('Root.Content.Promos', new TextField('PromoName2'));
       $fields->addFieldToTab('Root.Content.Promos', new HtmlEditorField($name = "PromoText2",$title = "Promo Text 2"));
       $fields->addFieldToTab('Root.Content.Promos', new ImageField('Promo2'));
       $fields->addFieldToTab('Root.Content.Promos', new TextField('PromoName3'));
       $fields->addFieldToTab('Root.Content.Promos', new HtmlEditorField($name = "PromoText3",$title = "Promo Text 3"));
       $fields->addFieldToTab("Root.Content.Promos", new ImageField('Promo3'));
       return $fields;
    }
    }

    Any thoughts would be helpful. The database is accepting content added to pages without my custom fields, so I know it is an issue with something I wrote...

  • maryfran
    Avatar
    Community Member
    12 Posts

    Re: Data won't save to in the fields I created [Solved] Link to this post

    If i had made sure the text fields were in the $db = array, I would have saved myself about 3 hours of frustration.

    1238 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.