Search code examples
phpdrupaldrupal-7field

Drupal get a value of a select list not a keys?


How can I get all options for a fields?

For example, There is a field with 3 options in allowed values, like option1, option2, option3.Is there any function which receive the field name and returns selected values not a keys ?

With this just return key of selected opinion

  print ($node->field_opinion['und'][0]['value'])

Solution

  • You can do this using list_allowed_values function :

    $key = $node->field_opinion['und'][0]['value'];
    $options = list_allowed_values('field_opinion');
    $label = $options[$key];