1

I have hundreds of webforms created from a single webform template. How do I programmatically export all webform submissions into a single csv? Note that this is not possible via views out of the box. One would have to create [webform_mysql_views.] (Combine Webforms to export multiple form results in a single CSV) This doesn't seem efficient.

  • Would you be interested in an alternative to the Views module, that can do exactly what you're asking for (so no need for "programmatically")? – Pierre.Vriens Mar 28 '16 at 16:23
  • Pierre - what is the alternative option? Most definitely interested. Thanks! – user59517 Mar 28 '16 at 17:27
0

As per your comment that you are interested in "an alternative to creating such CSV file programmatically": have a look at the Forena module (without using Views. Forena can do exactly what you're asking for (so no need for "programmatically").

As an example, create a custom "data block" (which is just an SQL statement) that fits your needs, to retrieve the webform data that you're interested in. Here is a (basic) example that I sometimes use for some testing:

SELECT s.nid AS node, s.sid AS submission, d.cid AS component, d.data AS fieldvalue
FROM {webform_submissions} s JOIN {webform_submitted_data} d ON s.sid=d.sid 
WHERE d.cid=3 AND s.nid=5
ORDER BY s.sid ASC

Then create a Forena "report" that uses this data block, and make sure that within "document types" you enable the "CSV" option. Here is the (basic) layout of such report to illustrate the idea:

<body>
<div id="webform_submissions_data_block" class="FrxTable" frx:block="drupal_cust/webform_submissions_data">
    <table>
      <thead>
        <tr>
          <th>node</th>
          <th>submission</th>
          <th>component</th>
          <th>fieldvalue</th>
        </tr>
      </thead>
      <tbody>
        <tr id="webform_submissions_data" frx:foreach="*">
          <td>{node}</td>
          <td>{submission}</td>
          <td>{component}</td>
          <td>{fieldvalue}</td></tr>
      </tbody>
    </table>
  </div>
</body>

After you saved the report and browse it, you'll have a "CSV"-hyperlink (upper right of the report). Just use that link and ... voilà, there is your CSV file (in this case with 4 columns, since that is what in my (basic) report I asked for.

If this makes sense, head of to the Community documentation of Forena to get you going (which includes pointers to video tutorials). Or use the documentation that comes with Forena.

Of course, building the appropriate SQL statement to perfectly fit your needs is going to be crucial. But apart from that, it's just basic usage of Forena.

Disclosure: I'm a co-maintainer of Forena.

  • Thanks Pierre! I will try this out and update the answer accordingly. I did not know about Forena before. – user59517 Mar 28 '16 at 19:25
  • Thanks for considering it (giving it a try). An don't worry you didn't know Forena, you're not the only one (who doesn't know what they are missing ...). If you run into new questions while trying to get going with Forena, just create a new question (and tag it with forena ... – Pierre.Vriens Mar 28 '16 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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