I'm working with webform to collect information on car relliabilty level.

I've set one dropdownlist to allow user choosing a car brand. As a car brand is selected, only the coresponding dropdownlist, with car models, is showing up (done with Webform Conditional).

All is working fine, but I realize each model dropdownlist is saving data in its own field in the database.

I want to analyse results by car brand and car models. What would be the best way to proceed?

Saving all models in one fields, when data are submitted? Maybe with a hook
Merging all car models after data submission in one unique field?

My test: http://fiabilidad-coche.blg.lt/?q=node/10

Any help or hint would be greatly appreciated.

2 Answers 2


Ok, I found a solution: I've used a presave hook. This hook is saving all values submitted by users in a hidden field called "model". A loop will be needed to read the 56 listboxes and save the only value the user have selected.

To do my test I've created a test webform, with only one listbox and one hidden field (this field created automatically my needed field "model" in my database). That speed up a little my tests:

First at all I've created a custom module with a "presave" hook In a new directory named "duplicated_data", I have create two files:

In the info file I've declared my module

name = Data Duplicate
description = Duplication Data for Webform
core = 7.x
package = Webform
dependencies[] = webform

In the module file I've written my php code

function data_duplicate_webform_submission_presave($node, &$submission) {
  $component_id = 1; // dropdownlist cid = 1
  $mem = $submission->data[$component_id][0]; // retrieve the submitted value
  drupal_set_message('datos :'.$mem); // print the result
  $component_id = 2; // cid = 2
  $submission->data[$component_id][0] = $mem; // save the data in the hidden field

Now I need to activate my custom module. Each time I make a choice in my dropdownlist/listbox and click on submit, the results will be saved in the database in both fields.

For my production webform , I need to create the loop in order to read all the 56 listbox values and save in my field "model" only the value from the selected listbox. It will be easy to catch it, because it will be the only one, different from NULL.

Hope it will be help somebody else!


Here I leave the final code:

function data_duplicate_webform_submission_presave($node, & $submission) {
  if($node->title == 'Encuesta') { // the hook will only work with this node
  for ($component_id = 2; $component_id < 58; $component_id++) { //loop into all my listboxes
  $mem = $submission->data[$component_id][0];
  if ($mem != NULL) { // save only data <> NULL => the user selected data.
  $submission->data[100][0] = $mem; // save the data in my field "model"
  drupal_set_message('Model : '.$mem); // optional, message with the value of the user selection.

Your Answer

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

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