Menu

CSV Formatting

Help
jweisberg
2008-03-07
2013-06-03
  • jweisberg

    jweisberg - 2008-03-07

    Does anyone know how to format the form fields to output to a CSV file so that the form field labels appear at the top of each column in excel and that each time the form is submitted, the data is plugged into rows beneath each corresponding label or field name?

    It would look like this:

    First Name    Last Name    Address 1    Address 2    City            State    Zip Code
    John             Smith            123 Main St.    Second Floor     Town Name    CA     00000
    Jack            Brown            9 South Plaza   Suite 2800    Town Name      AZ      00000
    Matt            Jones            10 Maple Drive                Town Name      NJ      00000

    Also - how to do the checkbox handling so that multiple options are placed in their own column?

     
    • TNTEverett

      TNTEverett - 2008-03-07

      Why can't you just use the "|" as the field separator when importing into Excel?

       
    • jweisberg

      jweisberg - 2008-03-10

      But how do you structure the processor php file to output the data as a tab deliminated .txt file or compatible file so that the data may be imported into excel with "|" as the field separator?

      I have the following in my processor php file:

      // Checkbox handling
      $field_1_opts = $_POST['field_1'][0]."
      ". $_POST['field_1'][1]."
      ". $_POST['field_1'][2];

      $fileLine = "FUNDS SELECTED: $field_1_opts
      INVESTOR INFORMATION: " . $_POST[' '] . "
      First Name: " . $_POST['field_2'] . "
      Last Name: " . $_POST['field_3'] . "
      Title: " . $_POST['field_4'] . "
      Organization: " . $_POST['field_5'] . "
      Investor Type: " . $_POST['field_6'] . "
      Address 1: " . $_POST['field_7'] . "
      Address 2: " . $_POST['field_8'] . "
      City: " . $_POST['field_9'] . "
      State/Province: " . $_POST['field_10'] . "
      Zip Code/Zone: " . $_POST['field_11'] . "
      Phone: " . $_POST['field_12'] . "
      E-mail: " . $_POST['field_13'] . "
      Questions/Comments: " . $_POST['field_14'] . "
      Country: " . $_POST['field_15'] . "
      Date and Time: " . $dtstamp . "

      ";
      $filename = 'kitrequest.txt';
      if (is_writable($filename)) {

                      if (!$handle = fopen($filename, 'a'))
                      {
                           echo "Cannot open file ($filename)";
                           exit;
                      }
                      if (fwrite($handle, $fileLine) === FALSE) {
                          echo "Cannot write to file ($filename)";
                          exit;
                      }

                      fclose($handle);

                  } else {
                      echo "The file  is not writable";
                  }

      include("confirm.html");

      ?>

       
      • TNTEverett

        TNTEverett - 2008-03-10

        Show me an example first 2 lines of your text file.

         
    • jweisberg

      jweisberg - 2008-03-10

      It first outputs the checkbox handling as such:

      FUNDS SELECTED: KYN
      KYE

      Here's a complete entry exactly as it is in the text file:

      FUNDS SELECTED: KYN
      KYE
      KED

      INVESTOR INFORMATION:
      First Name: Testy
      Last Name: Tester
      Title: Test
      Organization: Test
      Investor Type: Other
      Address 1: Test
      Address 2: Test
      City: Test
      State/Province: CA
      Zip Code/Zone: 90000
      Phone: USA
      E-mail: 2131234567
      Questions/Comments: test@test.com
      Country: Testing
      Date and Time: 03.10.2008, 09:48:30

       
      • TNTEverett

        TNTEverett - 2008-03-10

        OK, sorry I thought 3.0 produced the same text file as 2.09.  Email me a copy of your processor.php file and I'll fix it up for you.  I will create a second file with the format you are looking for. 

         
    • jweisberg

      jweisberg - 2008-03-10

      Sure, thanks!

      What is your email address?

       
  • Howard Canning

    Howard Canning - 2010-06-11

    Hi,
    I am interested in the solution to the above. I woulld like to know how the text file can be generated with comma delimiters in the beta version so i can import it into excel. I can delivery the data to eg details.txt but ideally would like to see the data delimited. I just use 3 fields eg:

    Name John
    Email abc@abc.com
    Mobile 09089898

    so that in excel I could have

    name          |  email          |              mobile
    john                1@abc.com          45645646

    I also tried with v2.09 but can't see any text file generated in this version or way to export the details.
    Thanks

     
  • Howard Canning

    Howard Canning - 2010-06-11

    my cuurent output is like this:
    Name: Howard  Mobile: 4554646546546 Email: gdfgfdgd@nn.nn

    even:
    col1                 col2               col3              col4            col5               col6
    name              Howard        Mobile         4544545     email            dffdfdgdg@hghg.com

    etc….

    would be perfect i.e csv would look like
    Name:, Howard,  Mobile,: 4554646546546, Email:, gdfgfdgd@nn.nn,

    THANKS

     
  • TNTEverett

    TNTEverett - 2010-06-11

    In 2.09 data file name is data.dat and it can be found in the admin folder.  This file has a preformatted header using "|" as the delimiter.  It can be changed if you want comma separated values. 
    Data written to the file can be found in the process.php file on a line that looks like this:
      $to_put .= $CompanyName."|".$YourName."|".$YourPhone."|".$YourFax."|".$YourEmail."|".$TotalUnpaidBalance."|".$NumberofAccounts."|".$TypeofAccounts."|".$OriginalUnderwriting."|".$AverageBalance."|".$AskingPricePercentage."|".$State."|".$Isyourcompanytheoriginalcreditor."|".$Ifnothowmanyinchainoftitle."|".$Weretheaccountsworkedinternallybytheoriginatorpostchargeoff."|".$Ifyeshowlong."|".$Weretheaccountsplacedwithanagencybytheoriginatorpostchargeoff."|".$Ifyeshowmanyagencies."|".$Ismediaavailable."|".$Didyourcollectionagencieshaveblanketsettlementauthority."|".$Ifyeswhatpercentageofbalancewasofferedforsettlement."|".$Ifyeswhatdiscountpercentagewasofferedforsettlement."|".$Weremasssettlementsoffered."|".$Ifyeswhatpercentageofbalanceofferedforsettlement."|".$Ifyeswhatdiscountpercentageofferedforsettlement."|".$Havetheaccountsbeenscrubbedforbankruptcy."|".$Havetheaccountsbeenscrubbedfordeceasedborrowers."|".$SpecialComments."|".$spreadsheet."|".$loandoc."\n";

    Again, these are separated by the "|" character and can be changed if that is what you want. 

     
  • Howard Canning

    Howard Canning - 2010-06-12

    Thanks. Can the same delimiter be applied to the delivery file in the beta version as I'd like to use image validation?

     
  • Robbie

    Robbie - 2010-11-08

    Can you clarify this? I used the online generator and the processor file does not have "$to_put .="

    Also, for the option of outputting the data to a file, is there a way to attach the file to the email? Or format the data in the email body so that one can copy and paste it into a spreadsheet and, for example, "Name: John" will fall into two columns? 

    I ask because I'm doing this for a friend who's not technically inclined and would like a solution where he can get and use the data on his own. So the database is not feasible, using ftp to get the .dat file is not simple for him, and unformatted data in an email body means time to copy and arrange it in a spreadsheet (though there are only eight straightforward fields).

    Thanks for a great form!

    R

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.