We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31191
    • 39 Posts
    Do of the contact form add-ons for Revolution allow you to dump the data from a user-filled form to a text or .csv file?
      perusing forums is where my comp sci degree got me.
      • 3749
      • 24,544 Posts
      At this point, it would take a custom hook snippet for FormIt, but a fairly simple one.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 31191
        • 39 Posts
        Thanks. I thought I’d post what I used to do this for anyone with future questions on it. As you said, pretty simple! This custom hook runs after the email hook and before the redirect.

        <?php
        $fp = fopen("/path/to/file/filename.csv", 'a');
        
        fputcsv($fp, array(
          $hook->getValue('first_name'), 
          $hook->getValue('last_name'),  
          $hook->getValue('email'), 
        ));
        
        fclose($fp);
        return true;


        This page helped -->http://rtfm.modx.com/display/ADDON/FormIt.Hooks#FormIt.Hooks-CustomHooks
          perusing forums is where my comp sci degree got me.
          • 3749
          • 24,544 Posts
          Glad you got it sorted. Thanks for reporting back. cool
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28099
            • 39 Posts
            I am trying to get formIt to write to CSV as well. I found this post and tried to implement it, but nothing seems to be happening.

            I took the above code and only changed the fields, saved it as a Snippet called "FormItCSV" and put it in the formIt folder under Snippets.

            Then I added to the list of hooks like so:
            &hooks=`spam,email,FormItCSV,redirect`


            When I submit the form it does everything BUT write to CSV. I’m not even certain that it is loading the snippet. If the snippet failed then it would not have redirected, right?

            Has anyone had any success getting formIt to write to CSV?
              • 31191
              • 39 Posts
              Is your csv file on the server writable? It should be 646 at least or 666. Also, check your path to the csv, it should the absolute path to the server.

              Something like:

              var/www/domain.com/filename.csv
                perusing forums is where my comp sci degree got me.
                • 28099
                • 39 Posts
                Ok, turns out there is a nice component that does all this:
                http://modx.com/extras/package/ditsformsaver

                Don’t know why this never turned up in my hours of Googling, but am grateful to have found it. Works great....
                  • 36704
                  • 131 Posts
                  Hi v2theg,

                  i tried to use your sample snippets but it not works on me,
                  Nothing saves on csv file.


                  here is my formit

                  [[!FormIt?
                  &hooks=`formit2csv,spam,email,redirect`
                  &emailTpl=`MyEmailChunk`
                  &emailTo=`[email protected]`
                  &redirectTo=`23`

                  ]]

                  <h2>Contact Form</h2>

                  [[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]

                  <form action="[[~[[*id]]]]" method="post" class="form">
                  <input type="hidden" name="nospam:blank" value="" />

                  <label for="name">
                  Name:
                  <span class="error">[[!+fi.error.name]]</span>
                  </label>
                  <input type="text" name="name" id="name" value="[[!+fi.name]]" />

                  <label for="email">
                  Email:
                  <span class="error">[[!+fi.error.email]]</span>
                  </label>
                  <input type="text" name="email" id="email" value="[[!+fi.email]]" />

                  <label for="subject">
                  Subject:
                  <span class="error">[[!+fi.error.subject]]</span>
                  </label>
                  <input type="text" name="subject" id="subject" value="[[!+fi.subject]]" />

                  <label for="text">
                  Message:
                  <span class="error">[[!+fi.error.text]]</span>
                  </label>
                  <textarea name="text" id="text" cols="55" rows="7" value="[[!+fi.text]]">[[!+fi.text]]</textarea>


                  <br class="clear" />



                  <div class="form-buttons">
                  <input type="submit" value="Send Contact Inquiry" />
                  </div>
                  </form>


                  And here is your snippets
                  <?php
                  $fp = fopen("assets/upload/filename.csv", 'a');

                  fputcsv($fp, array(
                  $hook->getValue('first_name'),
                  $hook->getValue('last_name'),
                  $hook->getValue('email'),
                  ));

                  fclose($fp);
                  return true;

                  The permission on that folder is 2775

                  Did i miss something? Any help?

                  Thanks
                    • 36704
                    • 131 Posts
                    Hi v2theg

                    I have found my mistake that was on my path settings was wrong and put the right path and it's working right now.
                    All of the data input in user's registration form was automatically save into my csv file.

                    But i have another question in this snippets, is there anyway to get the date & time stamp?
                    Can you teach me how to insert that inside this snippets?

                    Bobyray, please help me because my knowledge in programming was not good.

                    Thanks very much
                      • 3749
                      • 24,544 Posts
                      If you want to save the date/time to the DB, you probably want the PHP time() function:

                      http://php.net/manual/en/function.time.php


                      You can format it when you retrieve it with strftime():

                      http://www.php.net/manual/en/function.strftime.php


                      If, for some reason, you want to save it or display it in human-readable form, you can use the date() function:

                      http://php.net/manual/en/function.date.php

                      What is it that you want to do with the date/time?



                      ---------------------------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                      MODx info for everyone: http://bobsguides.com/modx.html
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting