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   375 Views

Avatar
oldsql

Community Member, 6 Posts

23 March 2014 at 1:21pm

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

Forum Moderator, 5513 Posts

23 March 2014 at 5:54pm

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

Community Member, 6 Posts

25 March 2014 at 12:06am

Thanks! That worked just fine :-)