Last active
December 18, 2015 12:19
-
-
Save alex-moreno/5782455 to your computer and use it in GitHub Desktop.
Modifying webform options with Drupal hook webform_select_options_info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; $Id$ | |
name = Your_Module Webform options | |
description = Preset options for Your_Module webform fields | |
package = "Your_Module" | |
project = Your Project | |
core = 6.x | |
version = 6.x-1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Reference: http://xebee.xebia.in/2011/06/14/drupal-webform-add-a-dynamic-select-option-list/ | |
* The following piece of code is based on the blog post above written by Anubhav | |
*/ | |
function your_module_custom_webforms_webform_select_options_info() { | |
$items = array(); | |
// if (function_exists('_get_node_titles')) { | |
$items['my_dealers'] = array( | |
'title' => t('Node titles'), | |
'options callback' => '_get_options', | |
); | |
// } | |
return $items; | |
} | |
function _get_options() { | |
$options = array(); | |
// Query to search for ... | |
$sql = "SELECT nid, title FROM {node}"; | |
$result = db_query($sql); | |
foreach ($result as $row) { | |
$options[$row->nid] = $row->title; | |
} | |
// Change this with the previous query | |
$options[] = "option 1"; | |
$options[] = "option 2"; | |
return $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment