Is it possible to add a node reference field using the Webform module?

If it is, how can I add it in my webform?


5 Answers 5


I done this but for a user reference by creating a new module and a new webform component.

This new component effectively recreates the user reference functionality and allows you to choose it on the webform. You could try the same approach to do it for a node reference.

Also there are some good examples in the webform examples to help you with the basics in creating a new component with hooks like _webform_defaults_component().

The main thing which will help you is the '#autocomplete_path' => 'autocomplete/node', in _webform_render_component() which you will need in the component.

...In the module add something like the below (obviously change for node lookup):

//create a url path for the autocomplete
function hook_menu() {
  $items['autocomplete/users'] = array(
    'path' => 'autocomplete/users',
    'title' => 'Auto Complete Users',
    //page callback to a custom function
    'page callback' => 'hook_autocomplete_users',
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
  return $items;

//custom function created to mimic auto complete functionailty
function hook_autocomplete_users($string = '') {
  $matches = array();
  $query = "SELECT u.name, u.uid FROM {users} u WHERE name LIKE LOWER('%s%%')";
  $result = db_query_range($query, $string, 0, 10);
  while ($user = db_fetch_object($result)) {
    $matches[$user->name.' uid:'.$user->uid] = $user->name;
  //print drupal_to_js($matches);

You will need to choose what you want in the node reference too as by default it would just be the nid which in an email would be pretty useless..

  • Thanks Westie, I will try this solution in the next days and I will let you know. Thank you very much. Mar 20, 2012 at 16:03

You should dump the old Webform module and take a look at Entity Form :)

It allows you to add for example Node reference field for your form. Were neat module!


Entityforms module uses the standard Drupal fields which means you can use any standard Drupal fields. For those of you who have used Webforms, this module brings Webform's functionality into the "standard" Drupal field / entity world.

While Webform is a great module with a huge following, it does not integrate with standard Drupal field or entity aware modules. So for Drupal 7 sites, it is recommended to use Entityforms module!

Like Webform, it integrates well with Rules module for form submission notifications and allows for complex notifications logic.


Check out Webform References module. I think it perfectly suits your case.

As the module page reads

Provides a webform component that can reference a node/term in webform. Currently, the module includes node/term reference components. It provides "Select List" and "Autocomplete" as widget. User reference will be added later.

function MY_MODULE_webform_select_options_info() {
  $items = array();
  $items['my_custom_list'] = array(
    'title' => t('Custom list'),
    'options callback' => 'MY_MODULE_custom_list'

  return $items;

function MY_MODULE_custom_list() {
  $my_custom_list = array(
    'foo' => 'bar',

  return $my_custom_list;

You now have a new pre-built option list. When you create a new field type "select options" you can choose "Load a pre-built option list" and there is your new list

Your Answer

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

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