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->type);

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

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

Here is the full function:

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

  // Update some component's value before it is saved.
  $component_id = 30;
  $submission->data[$component_id]['value'][0] = $flags;
}

What am I doing wrong? I'd love some help!

Comments

quicksketch’s picture

Status: Active » Fixed
$submission->data[$component_id]['value'][0] = $flags;

$flags is an array of data. If you want to store that as a string, you'll need to convert it from an array into a string.

This is generally outside the scope of the issue queue, we specifically avoid programming questions to help reduce the noise in the issue queue. StackExchange or IRC might be better venues for help on this sort of thing. I'm going to mark this fixed as a support request to keep it visible, but this is about as much as we can provide in the Webform queue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.