Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Get value of DropdownField not the ID

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

Page: 1
Go to End
Author Topic: 347 Views
  • oldsql
    Avatar
    Community Member
    6 Posts

    Get value of DropdownField not the ID Link to this post

    Hey,

    in the page.php I have this code:

       private static $db = array(
          ....
    'Glasart' => 'Text'
       );

    and this:

    public function getCMSFields() {
    $fields = parent::getCMSFields();
    ....
    $options = array("Kaffeeglas", "Weinglas", "Cocktailglas", "Bierglas", "Sektglas", "Wasserglas", "Sonstige");
    $fields->addFieldToTab("Root.Main", new DropdownField("Glasart", "Glasart", $options), 'Content');
    ....
    return $fields;

    and in the Page.ss:

    <h1>$Title - $Glasart</h1>

    But in the frontend I only see the ID of the selected value, but I want the value, for example "Kaffeglas".
    Any ideas ?

  • Willr
    Avatar
    Forum Moderator
    5503 Posts

    Re: Get value of DropdownField not the ID Link to this post

    Your array should look something like this then
    array(
    "Kaffeeglas" => "Kaffeeglas",
    "Weinglas" => "Weinglas"
    ..
    );

    If you don't want to write the same thing twice, you could use array_combine to generate that for you ($a = array_combine($a, $a))

    http://nz1.php.net/array-combine

  • oldsql
    Avatar
    Community Member
    6 Posts

    Re: Get value of DropdownField not the ID Link to this post

    Thanks! That worked just fine

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