While this module is almost useful, it's not nearly as useful as it could be. Currently when a webform is submitted with this module, it return's the node's title. That is the wrong way to go about doing things because the title is NOT the key. The nid is the key. Every drupal module uses the nid as the reference resource, not the title for very obvious reasons. This is because it's possible for more than 1 node to have the same exact title. This is a BUG imho and not a feature request. This module should return the NID not the title. You can then use node_load() to get the title if need be, but without the nid, you dont even have that option.

Here is an example array that I get when submitting the webform:

Array
(
    [submitted] => Array
        (
            [1] => test node
        )

    [details] => Array
        (
            [nid] => 62
            [sid] => 
            [uid] => 1
            [page_num] => 1
            [page_count] => 1
            [finished] => 0
        )

    [op] => Submit
    [submit] => Submit
    [form_build_id] => form-ad091159afd8f1acacc4522c0deb816f
    [form_token] => 0d9f8edec1f15c5fe2b0da7025b996bc
    [form_id] => webform_client_form_62
    [submitted_tree] => Array
        (
            [testview] => test node   <------ This is WRONG.  It should be  [testview] => 64  where 64 is the nid of the node that has a title of 'test node'.
        )

)

Comments

crystaldawn’s picture

Better yet, it should allow you to select which "Field" in the view to use as the "key" and which field to use as the "value". There are like 4 issues in the queue regarding this 1 issue with different ways to work around it. I believe the fields selection is probably the best method. If a view doesnt have at least 2 fields, then it shouldnt be allowed to be used as a viewselect.

Hervé Saladin’s picture

I have the same problem : the node's title is not reliable enough for me, I really need to get the nid.
It would allow me to write some custom tokens in order to fill some PDF forms (with FillPDF module) with some of the referenced node fields.

I can't understand why the title is recorded and not the nid : a reference is supposed to be based on a unique identifier, and moreover when I take a look at the HTML code of the form element I can see that the nid is used as the ID for entries, so why not store the selected ID and extract the node's title instead ?

@crystaldawn : I think your idea is a bit too complicated. I think the best thing to do is to use the node's ID as "key" since this form element is supposed to refence nodes ... and for the "value" the simplest (and - imho - the most flexible) solution is to use the view's output, so we can easily configurte it with View UI.

johnp’s picture

I had the same issue and fixed it by changing viewselect.inc. Now I can get the nids as I need them to be able to do some processing in a hook. The fix was in the function _webform_submit_viewselect and it became something like this. Not very shiny or polished, but it works.

function _webform_submit_viewselect($component, $value) {
  $options = _webform_viewselect_options($component['extra']['advanced']['advanced_view'],$component['extra']['advanced']['advanced_view_arguments']);

  if (is_array($value)) {
    foreach ($value as $key => $option_value) {
      // Handle options that are specified options.
      if ($option_value !== '' && isset($options[$key])) {
        // Checkboxes submit an *integer* value of 0 when not checked.
        if ($option_value === 0 && $options[$key] != '0' && $component['extra']['aslist'] !== 'Y' && $component['extra']['multiple'] === 'Y') {
          unset($value[$key]);
        }
        else {
          //$value[$key] = $options[$key];
          $node = node_load($option_value); 
          if($node) {
          	$value[$key] = $key;
          }
        }
      }
      else {
         die("q");
        unset($value[$key]);
      }
    }
    // Always save at least something, even if it's an empty single value.
    if (empty($value)) {
      $value[0] = '';
    }
  }
  return $value;
}

For multiple selections I get in return (supposed to return nids 5, 6, 7, 18, 139):

Array ( [value] => Array ( [6] => 6 [7] => 7 [5] => 5 [139] => 139 [18] => 18 ) ) 

For single selection I get (supposed to return nid 6):

Array ( [value] => Array ( [0] => 6 ) )

Works for me at the moment but should probably be tested more thoroughly.

In order to access the data without having to know the exact position of the form field, I used this recipe from stackoverflow, http://drupal.stackexchange.com/questions/7807/webform-add-data-along-wi..., letting me use the field name instead of the id

	// Load information about form components
	$comps = $node->webform['components'];
	$fields = array();
	
	//Extract the component info to get form_key=>cid to resolve relation
	foreach($comps as $cid => $comp_info){
	    $fields[$comp_info['form_key']] = $cid;
	}
	
	// Load the submitted data (field values)
	$data = $submission->data;
        // access value
        $data[$fields['my_webform_field_name']]
freakalis’s picture

Status: Active » Closed (fixed)

From beta3 nid/uid/term is the key and is being saved to database.