4

I am attempting to use PHP in Drupal rules to update the values in submitted webform submissions. I can access and view the data correctly. When I assign a new value to a field, it will even show up correctly if I use:

print $submission->data[61][0];

But, when I navigate to the submission results page, the field is not updated.

I tried using the webform_submission_update() function to push my change, but still no luck.

Question: How do I programmatically update an existing submitted webform submission in Drupal?

Code:

$submission = webform_menu_submission_load($nid, $sid);

// Two ways I've tried to update the data
$submission->data[61][0] = "testwork";
$submission->data[61]['value'][0] = 'Declined';

// If I do print $submission->data[61][0]; it will show the new value.

webform_submission_update($nid, $submission);

1 Answer 1

4

The problem was 2-fold:

I didn't use node_load() on the NID of the webform.

I didn't use the correct webform function to load the data.

// Load the node and submission.
$node = node_load(3333);
$sid = $list_itemb->sid;
$submission = webform_get_submission($node->nid, $sid);
    
// Change submission data.
$submission->data[61][0] = 'Update';
    
// Finally, update the submission.
webform_submission_update($node, $submission);
Sign up to request clarification or add additional context in comments.

1 Comment

How does this work in Drupal 9?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.