Jump to:

23456 Posts in 18905 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Newbie Question: CheckboxSetField

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1980 Views
  • tonito
    Avatar
    Community Member
    24 Posts

    Newbie Question: CheckboxSetField Link to this post

    <code>
    class Test extends Page {
    static $db = array(
       );
    static $has_one = array(
    );

       function getCMSFields() {
       $fields = parent::getCMSFields();

       $fields->addFieldsToTab(
       'Root.Content.Main',
       array(
          new CheckboxSetField(
        $name = "topics",
        $title = "I am interested in the following topics",
        $source = array(
        "1" => "Technology",
        "2" => "Gardening",
        "3" => "Cooking",
        "4" => "Sports"
        ),
        $value = "1"
       )
       )
       );
       
    return $fields;
    }

    }
    </code>

    I realize this is a very basic question, but I am new to silverstripe and I am stumped.

    How do I declare the variable "topics", as it stands, the checkboxes appear fine in the admin part, but I can't save them (they always revert back to the default value) nor display results.

  • Jedateach
    Avatar
    Forum Moderator
    227 Posts

    Re: Newbie Question: CheckboxSetField Link to this post

    Hi tonito,
    Try adding a database field to save the selection into. Your $db array becomes:

    static $db = array(
    'topics' => 'Varchar'
    );

    Because your checkboxsetfield also has the name 'topics' , the data will be saved into the 'topics' database field for each test page.

    Chances are you'll be wanting to do something more advanced than that. You should learn about the SilverStripe datamodel , perhaps also go through the tutorials.

  • tonito
    Avatar
    Community Member
    24 Posts

    Re: Newbie Question: CheckboxSetField Link to this post

    Thank you it's what I needed.

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