Jump to:

1970 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » Different field types in Create Page form

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

Page: 1 2
Go to End
Author Topic: 3680 Views
  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Different field types in Create Page form Link to this post

    To work with Silverstripe, you need to be kiinda' comfortable with OO and MVC patterns ...

    I will try to take a better look at the tutorials.... and OO and MVC. Thanks a lot for your patience

    <?php
    class Blabla extends Page {

    public static $db = array(
    'Companies' => 'Text'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));

    return $fields;

    }

    }

    class Blabla_Controller extends Page_Controller {

    public function init() {
    parent::init();
    }
    ?>

    flushing dies (no error but nothing after GhostPage)

    Victor

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Different field types in Create Page form Link to this post

    Yeah.. it isn't working code... Just a quick example to get the gist of it ...

    But other than a Curly bracket and some other source data ... it should work ...

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Different field types in Create Page form Link to this post

    OK, I will try to make it work. Thanks: it points me in some direction

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Different field types in Create Page form Link to this post

    OK, I almost got it

    <?php
    class TestPage extends Page {
    static $db = array(
    "Method" => 'Text'
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Main", new DropdownField("Method", "Select Method", array(
    'First','Second'
    )));
    return $fields;
    }
    }

    class TestPage_Controller extends Page_Controller {
    }
    ?>

    It stores, however, numerical values 0,1 instead of labels First, Second.

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Different field types in Create Page form Link to this post

    Yeah..

    change :

    array(
    'First','Second'
    );

    into something like

    array(
    'Key'=>'value',
    'Key'=>'value'
    );

    and it will store your key..

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Different field types in Create Page form Link to this post

    Thanks! This works (on the contrary to recommended on the tutorial page to store PageColor). So finally working code (in case someone else needs it):

    <?php
    class TestPage extends Page {
    static $db = array(
    "Method" => 'Text'
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Main", new DropdownField("Method", "Select Method", array(
    'First'=>'First Method',
    'Second' =>'Second Method'
    )));
    return $fields;
    }
    }

    class TestPage_Controller extends Page_Controller {
    }
    ?>

    3680 Views
Page: 1 2
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.