Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

share|improve this question
I found the answer for my problem here. drupal.stackexchange.com/a/91221/23451 – c232993 Nov 5 '13 at 13:14
up vote 7 down vote accepted

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..

share|improve this answer
Thanks Westie, I will try this solution in the next days and I will let you know. Thank you very much. – Tyler Durden Mar 20 '12 at 16:03

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.

share|improve this answer

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!

share|improve this answer

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.

share|improve this answer
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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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