Add value to field using hook_webform_submission_presave() I am at my wits end trying to use the hook_webform_submission_presave function on a webform that I have created for a Drupal 7 site. Ideally I would like to capture a list of nodes that a user has flagged and transfer that data into a field before the user submits their form. But the function is just not adding the data.

First I get the flags:

$flags = flag_get_user_flags($node-&gt;type);


Then I want to transfer that variable into a field with a component ID of 32.

// Update some component's value before it is saved.
  $component_id = 32;
  $submission-&gt;data[$component_id]['value'][0] = $flags;


Here is the full function:

function get_flags_webform_submission_presave($node, &amp;$submission) {
$nodes_list = array();
$title = '';
  // Get the flags.
  $flags = flag_get_user_flags($node-&gt;type);

  // Get the nodes.
  if (!empty($flags)) {
foreach ($flags as $flag) {
    $nid = $flad-&gt;entity_id;
    // Get node data. Delete to not get node titles.
    $node = node_load($nid);
    $title = $node-&gt;title;
    // Combine data.
    $nodes_list[] .= 'node/' . $nid . ' ' . $title . ",\n";
    }
  }

  // Update some component's value before it is saved.
  $component_id = 32;
  $submission-&gt;data[$component_id]['value'][0] = $nodes_list;
}


What am I doing wrong? I'd love some help!
flag_get_user_flags will return an array. so you have to handle it as an array not like a value.