Jump to:

1971 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: 3682 Views
  • Victor
    Avatar
    Community Member
    128 Posts

    Different field types in Create Page form Link to this post

    I am creating CustomPage.php

    and I would like to have certain fields in CMS form to be of "Options" or "RadioButton" or ... type
    Is it possible?

    Thank you in advance Victor

  • Fuzz10
    Avatar
    Community Member
    786 Posts
  • Victor
    Avatar
    Community Member
    128 Posts

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

    Thanks! But this documentation is a bit murky: Logically I would expect

    Test.php:

    <?php

    class TestPage extends Page {
    static $db = array(
    'Foobar' => 'Optionset',
    );

    static $has_one = array(
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Main', new OptionsetField(
    $name = "Foobar",
    $title = "FooBar's optionset",
    $source = array(
    "1" => "Option 1",
    "2" => "Option 2",
    "3" => "Option 3",
    "4" => "Option 4",
    "5" => "Option 5"
    ),
    $value = "1"
    );, 'Content');

    return $fields;
    }
    }

    class TestPage_Controller extends Page_Controller {

    }
    ?>

    return $fields;
    }
    }

    class TestPage_Controller extends Page_Controller {

    }
    ?>


    but flushing db results in an error.

    Victor

  • Fuzz10
    Avatar
    Community Member
    786 Posts

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

    You are confusing DB data field types : http://doc.silverstripe.com/doku.php?id=data-types&s=field%20types

    with Form field types :
    http://doc.silverstripe.com/doku.php?id=form-field-types

    You can use a Text field to store your values.

  • Victor
    Avatar
    Community Member
    128 Posts

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

    Yes, I looked again and it is clear (unless I am still confused) that

    'Foobar'=>'Text'

    However simple correction does not work: db flush still returns an error. I need to put somewhere description of the OptionsetField .

    Unfortunately I cannot find a sample code (which would also work for checkboxes and radiobuttons) and would greatly appreciate the sample code.

    Victor

  • Fuzz10
    Avatar
    Community Member
    786 Posts

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

    Here is a quick example...

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

    $fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));      

    Good luck !

  • Victor
    Avatar
    Community Member
    128 Posts

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

    Thanks, but I am still lost:

    If I do simply like:
    Test.php

    <?php
    static $db = array(
    'Companies' => 'Text',
    );
    $fields->addFieldToTab('Root.Content.Companies', new OptionsetField('Companies', '', $DataObjectSet->toDropDownMap('id','name')));
    ?>

    db flush does not generate a new page type even if I add

    class TestPage_Controller extends Page_Controller {

    }

    but trying encapsulate the code in

    <?php

    class TestPage extends Page {

    }

    bring flush error

  • Fuzz10
    Avatar
    Community Member
    786 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 ...

    Also, please take a very good look at the tutorials....

    Here is a more useful example....

    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();
       }
       

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