0

I've created a module to create a new pre-built option list for a webform select list - the kind you can select here: enter image description 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.

  • Just guessing here (haven't used D6 in a while), but I would've thought the code in your loops should be: $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
  • This isn't 6; it's 7. Perhaps that's the issue? The code is copied from a module I wrote a while back for a 6 database, and it worked there. – EmmyS Jun 1 '12 at 20:07
  • I just changed my code to reflect your comment, and it didn't make a difference. I'm really looking for info on how to debug this, not for someone to fix it for me. – EmmyS Jun 1 '12 at 20:13
  • Try adding the code from here to your index file, it should force all errors to be displayed to screen. For the record the DB layer changed a lot in Drupal 7 and that's definitely what's causing the error – Clive Jun 1 '12 at 20:15
  • 1
    Sorry I think I got the wrong end of the stick; for 'proper' debugging you should probably look at setting up XDebug. Then your site will pause on error and flag up the line that's causing the problem in the IDE, along with the exact exception that was thrown. It's a real time saver if you can get it set up – Clive Jun 1 '12 at 20:29

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.