Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Is it possible to add a node reference field using th webform module? If it is, how can I add it in my webform? Thanks in advance.

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

3 Answers 3

up vote 5 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);
  drupal_json($matches);
  //exit();
}

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

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

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

Your Answer

 
discard

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.