mariovalney/cf7-to-zapier

Sending CF7 Data as JSON Object

Closed this issue · 4 comments

Hello, i use the Contact Formular 7 with the add-on "repeatable fields" and the add-on "cf7-to-zapier" and send the data to a Webhook.
how can i send the data from a repeatable group as JSON Object?
or how can i format the JSON-Data like:

{
"variable 1" : "???????",
"variable 2" : "???????",
"group" : {"variable 3": "?????", "variable 4" : "???????"}

}

Please help me?

Hi. You can use our filter to add data.

In your case, you can check for $_POST and increase the object.

Check this:
https://wordpress.org/support/topic/additional-fields-through-additional-settings/#post-9707661

And this:
https://wordpress.org/support/topic/additional-headers-4/#post-12118058

I have added the following code in the functions-core.php of the Plugin, but now the formular do not send. The loading indicator rotates forever.

Here is the code:

add_filter( 'ctz_post_request_args', 'add_repeatable_cf7_groups' );
function add_repeatable_cf7_groups( $args ) {
	$data = json_decode( $args['body'] );

	$data['persons'] = [];
	$i = 1;
		while( isset( $data["Firstname__{$i}"] ) ) {
			$data['persons']["Firstname__{$i}"] = $data["Firstname__{$i}"];
		   $i++;
                }

 $args['body'] = json_encode( $data );
	
 return $args;
}

Thanks for the support

I'm not sure if your code works.
If it's stuck on loader, maybe it's receiving a 500 error on ajax request.

Let's try another filter: ctz_get_data_from_contact_form

function tims_ctz_get_data_from_contact_form( $data, $contact_form ) {
    $data[ 'persons' ] = [];

    $i = 1;
    while ( ! empty( $data["Firstname__{$i}"] ) ) {
        $data[ 'persons' ][ "Firstname__{$i}" ] = sanitize_text_field( $data[ "Firstname__{$i}" ] );
        $i++;
    }

    return $data;
}

add_filter( 'ctz_get_data_from_contact_form', 'tims_ctz_get_data_from_contact_form', 10, 2 );

Note: You must not change the plugin code. If you do, you will loose this changes on plugin update.

The best way is to create a new plugin or add to your theme (if it's not a custom theme, add to a new child theme).

Closing due to inactivity.
Thanks