Hello community,

Thanks for the great module.

I am looking for a solution where webform submissions are added to an XML datafile like below.

Thanks for feedback!

Frederik

<?xml version="1.0" encoding="UTF-8"?>
<records version="1">
<campaign id="TESTCAMPAIGN" />
<record id="90210">
<telephone_number>0600000001</telephone_number>
<initials>T.C.</initials>
<prefix>de</prefix>
<surname>Testconsument</surname>
<postal>9999ZZ</postal>
<street>Telecomlaan</street>
<housenumber>29</housenumber>
<housenumber_suffix>C</housenumber_suffix>
<city>Testerdam</city>
<product>Testsetje no. 30</product>
<color>Green</color>
</record>
<records version="2">
<campaign id="TESTCAMPAIGN" />
<record id="90212">
<telephone_number>0600000222</telephone_number>
<initials>T.C.</initials>
<prefix>de</prefix>
<surname>Testconsument</surname>
<postal>9999ZZ</postal>
<street>Telecomlaan</street>
<housenumber>29</housenumber>
<housenumber_suffix>C</housenumber_suffix>
<city>Testerdam</city>
<product>Testsetje no. 30</product>
<color>Green</color>
</record>
</records>

Comments

websmash’s picture

Issue summary: View changes
DanChadwick’s picture

Status: Active » Fixed

Webform doesn't offer that as a built-in format. I *think* the API allows additional formats to be defined -- you'd have to check the API file. Another thought would be to see if there is an XML output module for views and use the webform views integration.

Good luck.

Status: Fixed » Closed (fixed)

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

joelrotelli’s picture

Hi,

Here is a starting point to a solution to this problem.

I used the hook_webform_submission_insert() to create an XML file for each submission.


/**
 * Implements hook_webform_submission_insert
 * @param $node
 * @param $submission
 */
function hook_webform_submission_insert($node, $submission){

  $data = $submission->data;
  $components = $node->webform['components'];
  $array = array();
//Recreate an array with form_key (system name of a component) as key, and value
  foreach($components as $key => $component){
    $array[$component['form_key']] = $data[$key]['value'][0];
  }

  $xmlstr = format_xml_elements($array);

   //Just setting the filename with the webform ID and the submission ID
  $filename = 'webform-'.$node->nid.'-submission-'.$submission->sid.'.xml';

  //An example for storing the file, but it's not a good idea to store it in public folder.
  file_save_data($xmlstr, 'public://submissions/'.$filename);

}
joelrotelli’s picture

You also need to set an XML header : $xmlstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
";