You are here

function webform_submission_update in Webform 7.3

Same name and namespace in other branches
  1. 5.2 webform_submissions.inc \webform_submission_update()
  2. 6.3 includes/webform.submissions.inc \webform_submission_update()
  3. 6.2 webform_submissions.inc \webform_submission_update()
  4. 7.4 includes/webform.submissions.inc \webform_submission_update()

Update a webform submission entry in the database.

Parameters

$node: The node object containing the current webform.

$submission: The webform submission object to be saved into the database.

Return value

The existing submission SID.

1 call to webform_submission_update()
webform_client_form_submit in ./webform.module
Submit handler for saving the form values and sending e-mails.

File

includes/webform.submissions.inc, line 53
This file is loaded when handling submissions, either submitting new, editing, or viewing. It also contains all CRUD functions for submissions.

Code

function webform_submission_update($node, $submission) {

  // Allow other modules to modify the submission before saving.
  foreach (module_implements('webform_submission_presave') as $module) {
    $function = $module . '_webform_submission_presave';
    $function($node, $submission);
  }

  // Update the main submission info.
  drupal_write_record('webform_submissions', $submission, 'sid');

  // If is draft, only delete data for components submitted, to
  // preserve any data from form pages not visited in this submission.
  if ($submission->is_draft) {
    $submitted_cids = array_keys($submission->data);
    if ($submitted_cids) {
      db_delete('webform_submitted_data')
        ->condition('sid', $submission->sid)
        ->condition('cid', $submitted_cids, 'IN')
        ->execute();
    }
  }
  else {
    db_delete('webform_submitted_data')
      ->condition('sid', $submission->sid)
      ->execute();
  }

  // Then re-add submission data to the database.
  $submission->is_new = FALSE;
  webform_submission_insert($node, $submission);
  module_invoke_all('webform_submission_update', $node, $submission);
  return $submission->sid;
}