0

I am building a online purchasing system, and I use a Webform to gather clients' personal information.

A problem rises when I want to append some external data (which is not important enough to be included as a field in my registration form) to the webform before the submission.

What should I do? (I used hook_webform_submission_presave(), but it seems to me that it can only be used to change data, not adding additional data.)

Here's my presave hook; it works, but it's not serving my purpose.

function hook_webform_submission_presave($node, &$submission) {
  // Update some component's value before it is saved.
  if ($node->nid == 0) {
      $component_id = 1;
      $submission->data[$component_id]['value'][0] = 'foo';
  }
}
3
  • Do you only want to show data (like a markup field) or do you want this "unnecessary" data to be saved into the database as well?
    – devunder
    Apr 3, 2013 at 22:29
  • To be saved in database as well!
    – movila
    Apr 5, 2013 at 17:33
  • Perhaps I'm misunderstanding you but if you just want to save some data on webform submission which doesn't have to be manipulated by data entered in the webform fields by the user just save this data to the database then within that function :)
    – devunder
    Apr 6, 2013 at 21:09

1 Answer 1

1

You can't create a new value to non-existing field, since the data has no place to save to the database. Ideally you should create a hidden field for your data and modify it in your handler on presave event or use hook_ENTITY_TYPE_presave. If you have multiple values to add, serialize it or save into JSON and assign to the hidden value.

You can also use Computed token field where you can define and place your custom token (with any dynamic data) into value of that computed field which can fetch and store the data dynamically.

Related: Is there a webform way to store additional data on a submit handler?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.