Way to code A Programming Blog

June 17th, 2012

How to get Values from dropdown type field in drupal

drupal, by Bikash kumar Sundaray.

In drupal we can create fields through UI given by Drupal.

Like we can create the list type field and also we can put more and more data to that fields using the UI,

But its really a hard job to get those values without the knowledge of Drupal Core coding.

At time of storing those values ZERO knowledge of drupal coding is required but to get those valuse to

use it in other modules you need to understand about the Drupal Database structure as well as few lines of code.


After creating a field in Drupal we can head for the database and just search for a table called field_config.

There you can find a column called field_name . Just Search for your field name that you have created at

the type of field creation and Copy that field name from that table.


In your own Drupal module you need to write just two lines of code like follows

$dropDownListData = field_info_fields();
$optionsdesc= list_allowed_values($dropDownListData["field_mygroup"]);

In the above example field_mygroup is the field name that i copied from field_config database table.

$optionsdesc contains the array of data in key value pair (associative array).

The contains of this variable will be something like this

$optionsdesc = array (1=> 'jatni'   , 2=> 'bhubaneswar'  , 3=>'orissa')


Just use with drupal form to create a drop down list by own like follows.

$form['desc_id'] = array(
'#type'          => 'select',
'#title'         => t('Name of the description'),
'#options'       =>$optionsdesc,
'#default_value' => 0,
'#required'      => TRUE,

This how we can retrieve drupal’s data from database and create the field of own wish.

VN:F [1.9.20_1166]
Rating: 5.4/10 (7 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 2 votes)
How to get Values from dropdown type field in drupal, 5.4 out of 10 based on 7 ratings
Print Friendly

Back Top

Responses to “How to get Values from dropdown type field in drupal”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *


three − = 0