Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

Get value of DropdownField not the ID


Reply

3 Posts   364 Views

Avatar
oldsql

23 March 2014 at 1:21pm Community Member, 6 Posts

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 ? :-)

Avatar
Willr

23 March 2014 at 5:54pm Forum Moderator, 5511 Posts

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

Avatar
oldsql

25 March 2014 at 12:06am Community Member, 6 Posts

Thanks! That worked just fine :-)