I am trying to populate the webforms pre-built option list using a custom module. It works when manually including the values in the module, but when I try to query an external database to get the options it fails. Below is my code. I know that the database works, because views is currently able to get data using that connection and the query works when implemented directly in MySQL.


function mymodule_webform_select_options_info() {
    $items = array();
    $items['user_name'] = array(
        'title' => t('User Name'),
        'options callback' => '_webform_get_user_names'
    return $items;

function _webform_get_user_names()
     $user_names = array();
     $query = 'SELECT userID,userName FROM user_name';
     $select = db_query($query);
     while ($row = db_fetch_object($select)) {
         $id = $row->userID;
         $user_names[$id] = $row->userName;
     return $user_names;
  • Are you using drupal 6 or 7? – Clive Mar 16 '14 at 11:59
  • I am using Drupal 7 – John Mar 16 '14 at 12:05
  • You're using DB API code from Drupal 6... – Clive Mar 16 '14 at 12:06
  • When I throw in WHERE restrictions to the queries it is saying that the column is not found. Is there anyway to confirm that it actually is connecting to the database and finding the table correctly? – John Mar 16 '14 at 12:07
  • I'm confused when I look at drupal.org/node/310072, it seems that the only real difference is that the table name is in curvy brackets. When I do that it still does not work. Note: I am assuming no where statements here. But now it provides the following error: Notice: Undefined index: aslist in webform_select_options_ajax() – John Mar 16 '14 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.