I am trying to link the results from a webform comment survey to content that was previously generated within a site so that the webform_submissions table in the database shows the node those answers are attached to.

I am planning to use a "node reference" dropdown to the content type I need, but that's as far as I've gone.

Any ideas or suggestions are most appreciated.

2 Answers 2


You can create your own predefined lists by using the webform_webform_select_options_info() hook.

* Implements hook_webform_select_options_info().
function yourmodule_webform_select_options_info() {
  $items = array();
  $items['contentchoice'] = array(
    'title' => t('Content Choice'),
    'options callback' => 'webform_options_yournodes',
  return $items;

Then generate your list of nodes using

* Webform options info callback.
function webform_options_yournodes() {
  $mynodes = array(
  //build your array up here
  return $mynodes;

Add to webform a select options widget. Then in your implementation of hook_form_alter

function YOURMODULENAME_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'your_webform_name') {
        $nodes = array();
        /*The WHERE section in the query needs to be adjusted to meet your requirements or removed at all if you need to have all nodes in the dropdown*/
        $results = db_query('SELECT * FROM {node} WHERE type=:type', array(':type' => 'article'));
        foreach($results as $result) {
            $nodes[$result->nid] = $result->title;
        $form['submitted']['your_select_widget_name']['#options'] = $nodes;

I assumed that you use D7. For D6 there might be slight differences in the code.

  • I'm on D6, but it's my fault not having mentioned it. Thanx Alex. :)
    – MauF
    Apr 27, 2012 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.