• Resolved kusalo

    (@kusalo)


    Hi Arshid,

    Many thanks for your offering. As others have commented “it does what it says it does.” – and well.

    I would like to add to your code, specifically to have it write the new input to a CSV on the server. I am a tolerable PHP writer but would like your suggestion as to where to do this; I could spend a lot of time experimenting.

    My first guess would be in: database-for-wp-forms.php in function WPFormsDB_save() but a few words from you could save me a lot of time.

    Once the data is on the server I can merge and manage easily enough.

    Thank you.
    Kusalo

Viewing 1 replies (of 1 total)
  • Thread Starter kusalo

    (@kusalo)

    Here is a brief breakdown of my process…

    There may be a better entry point but: database-for-wp-forms.php worked fine.
    function WPFormsDB_save () about line 93
    I tested using a std wpForms contact form; first/last/email

    First get definition on data.

    // traverse array = 18 = multi-dimension array
    $howMany = count($fields, COUNT_RECURSIVE);
    $entryRead= print_r("$entry", true); // set array into a variable
    
    // http wrapper can't open file. Use root or relative path.
    // use plugin dir as easier reading via ftp on making changes
    $dbURL = $_SERVER['DOCUMENT_ROOT'].'/wp-content/plugins/database-for-wpforms/database-for-wp-forms/';
    // write array to file
    $fh = fopen($dbURL.'testArray.txt', "w+"); if (flock($fh, LOCK_EX)) { fwrite($fh,$entryRead); flock($fh, LOCK_UN); } fclose($fh);
    
    /*
    $entryRead for $entry = testArray.txt
    Array
    (
        [fields] => Array
            (
                [0] => Array
                    (
                        [first] => xxxxx
                        [last] => yyyyy
                    )
                [1] => [email protected]
                [2] => the message here
            )
        [id] => 540
        [nonce] => e9...a
        [author] => 1
        [post_id] => 285
        [submit] => wpforms-submit
        [token] => 112f...bda
    )
     */

    With array construction visible it is easy enough to compile data as you wish. eg.

    $firstName = $entry['fields'][0]['first'];
              etc.

    Once the CSV exists it is easier to use:

    $handle = fopen($dbURL.'xxx.txt', "a"); // 'a' for append
    fputcsv($handle, $yourCompiledEntry);
    fclose($handle);

    I hope this is useful.

Viewing 1 replies (of 1 total)
  • The topic ‘add csv write to server’ is closed to new replies.