Reputation: 231
I'm sort of new to Drupal 7.
I am using Drupal Form API and I need to use a drop-down showing a list of states via the mymodule_forms
hook.
$form['work_state'] = array(
'#title' => t('Work State'),
'#type' => 'select',
...
);
I already have a list of states defined in a Content Type field.
How would one go around loading the Content Type (ie: forms_stipend) and retrieving the field (ie: field_states). After that is retrieved, I can start populating the available list of states into the code shown above.
Thanks in advance for your help as they're always appreciated!
Upvotes: 2
Views: 1834
Reputation: 36957
Assuming your field is a list type, you can grab the allowed values from the field using the field_info_field()
function:
$info = field_info_field('field_states');
$options = $info['settings']['allowed_values'];
$form['work_state'] = array(
'#title' => t('Work State'),
'#type' => 'select',
'#options' => $options
);
Upvotes: 3