Action and Filter Hooks – PRO Version

Action and Filter Hooks – PRO Version

We’ve expanded the capabilities of CF7 Google Sheet Connector by leveraging its  Action and Filter Hooks.

If you’re also using another CF7 addon plugin called “CF7 – Repeatable Fields” and wish to send the repeated field entries to Google Sheets, then you can achieve this by adding the following code to your active child theme’s functions.php file.

If you’re working with the main theme, it’s recommended to create a child theme and then include this code in its functions.php file.

/**
* Hook - apply_filters( 'gsc_filter_form_data', $data, $form );
* As Repeatable Fields have multiple data we need to pass values to Google Sheet in Array Format
*/
add_filter('gsc_filter_form_data', function ($data, $form) {
    $output = [];

    // If your form id is in the given array then proceed
    if (in_array($form->id(), [147, 170])) {
        // Get the Posted data provided by CF7 on form submission.
        $posted_data = WPCF7_Submission::get_instance()->get_posted_data();
        $row = $data;

        // Get count for any one field to loop and get the count of repeatable fields
        $counter = 0;
        foreach ($posted_data as $key => $values) {
            if (is_numeric(strpos($key, "your-email"))) {
                $counter = $counter + 1;
            }
        }
        
        // Loop and create array values
        for ($i = 1; $i <= $counter; $i++) {
            $row['your-email'] = $posted_data['your-email__' . $i];
            
            // for radio, dropdown and checkbox
            $row['your-radio'] = $posted_data['your-radio__' . $i][0];
            $row['your-menu'] = $posted_data['your-menu__' . $i][0];
            $row['your-checkbox'] = $posted_data['your-checkbox__' . $i][0];

            $output[] = $row;
        }
    }

    return $output;
}, 10, 2);

Note: You have to simply pass the Form ID and also the field names.

if (in_array($form->id(), [147, 170])) {…} whereas 147 and 170 are a Form ID which you have to change, as per your Form ID.

You will get the Form ID from the Contact Form edit link

 

Go to Top