You are here

function webform_rules_client_form_submit in Webform Rules 6

Same name and namespace in other branches
  1. 7 webform_rules.module \webform_rules_client_form_submit()

Custom submit handler for webform submissions.

This is needed to catch submissions of saved webform drafts as hook_webform_submission_insert() only fires once and its not possible in hook_webform_submission_update() to check if the data has been submitted before (e.g. saved as draft).

1 string reference to 'webform_rules_client_form_submit'
webform_rules_form_alter in ./webform_rules.module
Implementation of hook_form_alter().

File

./webform_rules.module, line 65
Adds rules integration for webform submissions.

Code

function webform_rules_client_form_submit($form, &$form_state) {

  // If the webform is NOT completed, don't run the submit handler!
  // This is relevant for multistep forms.
  if (!$form_state['webform_completed']) {
    return;
  }

  // If we've got to this point, then we are not mid-way through a form submission.
  $values = $form_state['values'];

  // Check if user is submitting as a draft.
  if ($values['op'] == t('Save Draft')) {

    // Saving the webform as draft is handled by hook_webform_submission_insert().
    return;
  }
  if ($form['#is_draft'] && isset($form_state['values']['details']['sid'])) {
    $submission = $form['#submission'];

    // Map submitted data to submission data.
    foreach ($form_state['values']['submitted'] as $cid => $value) {
      if (isset($submission->data[$cid])) {
        $submission->data[$cid]['value'] = $value;
      }
    }

    // Invoke event.
    webform_rules_rules_invoke_event($submission, $form['#node'], 'submit');
  }
  return;
}