Does anyone have any suggestions (e.g. code snippet) on how to export results and download the file with the field key instead of the label?
For example, getting a field key like 'program_completion' in the excel or text file instead of the entire question like 'What is your anticipated date of graduation or program completion?'. This would make the file much cleaner.

CommentFileSizeAuthor
#2 webform_export_header_format.patch5.57 KBjeffam

Comments

daengo’s picture

Status: Active » Closed (fixed)

I found the answer.
Find the file in the components folder for your component (i.e. select.inc, textfield.inc, textarea.inc, etc). Open the file and find
function _webform_csv_headers_ (the function will be different depending on which component type. For example function _webform_csv_headers_select for a select component). Change $header[2] = $component['name'] to $header[2] = $component['form_key'];. This must be done for all component types in your webform. Go back to the file download. Download the file and the form_key will be in the headers instead of the 'name'. You could also decide whether to remove the extra headers or leave them.

jeffam’s picture

Version: 6.x-2.8 » 6.x-3.4
Status: Closed (fixed) » Needs review
StatusFileSize
new5.57 KB

Sorry if I should have opened a new bug rather than resurrecting this one, but I had the same issue, and I solved it the same way, but as an option rather than a complete replacement.

Here's the patch. Hope it's useful to someone.

quicksketch’s picture

Interesting, thanks jeffam. I'm not sure about adding this as an option but I'll give it a try and see how it looks. Thanks for the patch!

quicksketch’s picture

Status: Needs review » Closed (won't fix)

I looked at this issue again and I don't think it's an option that I will be adding to Webform. Thanks for the patch but options like this are likely more obscure than they are helpful.

mstrelan’s picture

This is really helpful for me. I have many fields with the same name, but the user can enter in 4 or 5 different values, so I am differentiating between them with the field key. Now the client wants to mail merge in to a Word document and its rather troublesome trying to map to the right field.

Patch in #2 applies cleanly and seems to work well.

johnlaine’s picture

I agree with post#5. I use a webform to collect data to use with a word doc mail merge to create closing documents on the sale of a home.
I use fieldsets to make the form easier for my customers to enter the data but this means I have many duplicate fields, such as "address" (one for the buyer, seller, property itself, etc)
The Field Key is unique so this makes things a lot easier than using the Label which is not.

jeffam’s picture

I still need to maintain this patch for one of my clients, so I finally fixed up a sandbox repo that tracks the main webform releases but includes the changes I made to allow using fieldkeys as exported CSV headers.

Sandbox is here: http://drupal.org/sandbox/jeffam/1215106