Skip to content

Instantly share code, notes, and snippets.

@graceman9
Last active August 29, 2015 14:05
Show Gist options
  • Save graceman9/e906e958858a465009b1 to your computer and use it in GitHub Desktop.
Save graceman9/e906e958858a465009b1 to your computer and use it in GitHub Desktop.
Drupal 7: form api options from specific entity (node_type)
<?php
$entity_type = 'node';
$bundle_name = 'gift';
$fields = field_info_instances($entity_type, $bundle_name);
$options = array();
foreach ($fields as $name => $field) {
$options[$name] = $field['label'];
}
$form['field_price'] = array(
'#type' => 'select',
'#title' => t('Price'),
'#options' => $options,
'#default_value' => variable_get('field_price', ''),
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment