I've created a module to create a new pre-built option list for a webform select list - the kind you can select here:
My code looks like this:
/**
* Implementation of hook_webform_select_options_info().
* See webform/webform_hooks.php for further information on this hook in the Webform API.
*/
function populate_webform_dropdowns_webform_select_options_info() {
$items = array();
$items['get_states_provinces'] = array(
'title' => t('States/Provinces'),
'options callback' => 'populate_webform_dropdowns_options_get_states'
);
$items['get_countries'] = array(
'title' => t('Countries'),
'options callback' => 'populate_webform_dropdowns_options_get_countries'
);
return $items;
}
/**
* Build an options list for use by webforms.
*/
function populate_webform_dropdowns_options_get_states_provinces() {
$options = array();
$query = db_query("SELECT nick, name FROM ismi.list_states ORDER BY name");
while ($row = db_fetch_array($query)) {
$options[] = $row['nick'] . "|" . $row['name'];
}
return $options;
}
function populate_webform_dropdowns_options_get_countries() {
$options = array();
$query = db_query("SELECT country_id, name FROM ismi.country ORDER BY name");
while ($row = db_fetch_array($query)) {
$options[] = $row['country_id'] . "|" . $row['name'];
}
return $options;
}
The two choices (states/provinces and countries) do show up in the dropdown list of prebuilt options, but when I choose one, it does not fill the options in to the Options field (it does fill in if I use one of the Drupal-provided prebuilt lists) and when I try to save, it tells me the Options field is required. I'm guessing that there's a SQL error (I'm trying to pull these options from a different database), but I don't know how to debug something like this. I've tried using Firebug for Drupal, but because the query isn't being run (I don't think) when the page initially opens, it's not displaying the query in the SQL tab. How can I go about debugging this? I'm perfectly fine with writing to my server's error log, but that requires me to write variables to the log - I want to see any errors that occur.
$options[$row['nick']] = $row['name'];
and$options[$row['country_id']] = $row['name'];
...otherwise I don't think the select element will render the options properly – Clive♦ Jun 1 '12 at 18:38