Add a hook to allow a submission to be intercepted and altered by another module.
This is different to issue 2106815 in that it modifies the submission rather than the form itself, and it is for Drupal 7 not 6.

Comments

andrewfn’s picture

Status: Active » Needs review
StatusFileSize
new439 bytes

This patch is working fine on my production site.

andrewfn’s picture

I thought a demo function might be useful, since it took me some time to figure out how the $submission object worked.

/* Demo function to demonstrate hook_webform_service_submission_alter()
*/
define("FIRST_NAME", 1); //define field numbers from your webform
define("LAST_NAME",  2);

function mymodule_webform_service_submission_alter(&$submission) { // mymodule should be the name of your module
  $first = $submission->data[FIRST_NAME][0]; //get a value submitted by the user
  $last = $submission->data[LAST_NAME][0];

  // demo operation: "the first shall be last and the last first"
  $submission->data[FIRST_NAME][0] = $last; // write a new value back
  $submission->data[LAST_NAME][0] = $first;
}

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Brilliant! The patch works & allowed me to implement some custom form validation & error handling (since the regular Webform validation doesn't seem to work at all with this module over a REST endpoint).

RTBC.

Custom module code example:

function modulaname_webform_service_submission_alter(&$submission) {
  $somevar = $submission->data[5][0];
  if ($somevar != 'a required value') {
    header('HTTP/1.1 422 Unprocessable Entity');
    exit();
  }
}

tyler.frankenstein’s picture

Status: Reviewed & tested by the community » Fixed

Looks good, thank you!

Status: Fixed » Closed (fixed)

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