0

Currently I am trying to transfer data from a repeater field in Wordpress Formidable Forms to a list in a CRM system known as ActiveCampaign.

Unfortunately the ActiveCampaign Add-On does not recognise fields inside the repeater field.

When exporting the Child Form, I get exactly what I want. Is there any way to export this file as soon as an entry is created?

Any support would be greatly appreciated.

Dhruv
  • 1

1 Answers1

0

Maybe this link can help you: https://www.fdmdigital.co.uk/export-a-form-entry-to-csv-on-submit/

add_action('frm_after_create_entry', 'create_csv', 30, 2);
function create_csv($entry_id, $form_id) {
if ($form_id == 1234) { //replace 1234 with the id of the form

    // Collect the form data - Add a new row for each field you want to export and give it a unique name
    $firstName = isset($_POST['item_meta'][1537]) ? $_POST['item_meta'][1537] : '';
    $lastName = isset($_POST['item_meta'][1538]) ? $_POST['item_meta'][1538] : '';
    $email = isset($_POST['item_meta'][1540]) ? $_POST['item_meta'][1540] : '';
    $organizationId = isset($_POST['item_meta'][1547]) ? $_POST['item_meta'][1547] : '';
    $organizationName = isset($_POST['item_meta'][1548]) ? $_POST['item_meta'][1548] : '';
    $createdAt = isset($_POST['item_meta'][1555]) ? $_POST['item_meta'][1555] : '';

    // The header row of the CSV - Add a name for each field in the form
    $header = "firstName,lastName,email,organizationId,organizationName,createdAt\n";

    // The data of the CSV - Add each of the form fields listed above
    $data = "$firstName,$lastName,$email,$organizationId,$organizationName,$createdAt\n";

    /*
     * The file name of the CSV.
     * 
     * NB: To save a single file per entry you will need to make the file name unique 
     * This can be done using the entry ID or the date & time stamp by including the hour, minutes & seconds. 
     * E.g at 12:38:43 the file will be named "TestUser-21-02-05-12-38-43-request.csv".
     * One second later the time (and file name) will be "12:38:44".
     * Then a new file "TestUser-21-02-05-12-38-44-request.csv" will be created.
     * How you name the file will determine if you have a new file for each entry, a new file per user or a single file with all entry data.
     */

    $fileName = dirname(__DIR__, 3) . "/your-project-folder/" . $refUserId . "-" .$createdAt . "-request" . ".csv";

    /*
     * Create the CSV file.
     * If file exists, append the data to it. Otherwise create a new file.
     */
    if (file_exists($fileName)) {
        // Add only data. The header is already added in the existing file.
        file_put_contents($fileName, $data, FILE_APPEND);
    } else {
        // Add CSV header and data.
        file_put_contents($fileName, $header.$data);
    }
}

}

Gamersea
  • 23
  • 4