We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51474
    • 27 Posts
    Is there a way to modify formit plugin's excel format?


    All my output display in 1 column.


    I try look into formit system settings, it seems they doesn't have any excel column settings for me to modify.

    Since formIt has limitation on exporting pretty format excel, So I use FormSave ( https://rtfm.modx.com/extras/revo/formsave ) plugin for me to view & export data.

    But when I export CSV, the csv seems doesn't have any header attached...
    https://www.youtube.com/watch?v=cXh4YwLZahY

    May I know FormSave function have settings to modify the csv header and fieldsname?

    I've seen the documentation has only 3 hooks for me to modify which is
    fsFormTopic
    fsFormFields
    fsFormPublished

    I'm just wondering do they have example : fsFormFieldsName, fsFormHeader for me to modify the hook & excel?

    Thanks!

    This question has been answered by sottwell. See the first response.

    [ed. note: pohkit last edited this post 8 years, 3 months ago.]
    • discuss.answer
      FormSave is getting old and hasn't been developed for three years. The FormitSaveForm hook that comes with FormIt was last worked on 6 months ago. The file of interest is core/compontents/formit/processors/mgr/form/export.class.php

      It doesn't export "Excel" format, it exports .csv, which Excel can import.
      $fileName = 'formit-export-'.time().'.csv';
      


      Looking at export.class.php it doesn't appear to have any extra features, it just builds a plain-vanilla .csv file. It just creates an array of the form fields and feeds that array to the PHP fputcsv() function.
      http://php.net/manual/en/function.fputcsv.php

      This would be a good enhancement, though - options to insert a header row based on the fieldnames being exported, and to set the field delimiter. Maybe even an option to set the filename.

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
        • Ok. Did some testing. This formit snippet
          [[!FormIt?
             &hooks=`FormitSaveForm`
             &formFields=`name,email,text`
             &fieldNames=`name==Name,email==Email,text==Message`
          ]]

          Produces this .csv
          IP;Date;Name;Email;Message
          ::1;"2016-01-04 9:39 am";"Susan Ottwell";[email protected];"This is a test."
          


          So it has a header row by default, you can select which fields to save and what to name them for the .csv header.



          [ed. note: sottwell last edited this post 8 years, 3 months ago.]
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 51474
            • 27 Posts
            Quote from: sottwell at Jan 04, 2016, 08:46 AM
            Ok. Did some testing. This formit snippet
            [[!FormIt?
               &hooks=`FormitSaveForm`
               &formFields=`name,email,text`
               &fieldNames=`name==Name,email==Email,text==Message`
            ]]

            Produces this .csv
            IP;Date;Name;Email;Message
            ::1;"2016-01-04 9:39 am";"Susan Ottwell";[email protected];"This is a test."
            


            So it has a header row by default, you can select which fields to save and what to name them for the .csv header.




            Hello, Thanks for the Answer!
            Somehow I use your suggested hooks method.

            and then I modifed my export.class.php

            from
            fputcsv($fp, $keys, ';');

            to
            fputcsv($fp, $keys, ',');


            from
            fputcsv($fp, array_merge($defaultArr, $objectArray['values']), ';');

            to
            fputcsv($fp, array_merge($defaultArr, $objectArray['values']), ',');


            after that I can display correct method/column of .csv files on my macs and google drive.