[Forminator Pro] How to export submissions data into a json file?

Hello, I would like to know how to achieve this without using Zapier for it. There’s a way to export the Forminator submissions data into a JSON file to a webhook?. Thank you.

  • Premier Business Systems
    • WPMU DEV Initiate

    It was suggested to do the following:

    1 – Wrap the inputs in a form tag
    2 – Give the form a method attribute of “POST”
    3 – Give it an action attribute to the webhook I intend to send it to.

    <form action=”webhook URL” method=”POST”>

    <inputs>

    <input type = “submit” value=”send”>
    </form>

    Can you guys please help me with this as an option for my forms?

  • Adam
    • Support Gorilla

    Hi MC-Net Services

    Thanks for response!

    With Forminator, this is not a way to do this. You need a custom code that will hook to one of the Forminator’s “submission” action hooks and then “intercept” form data from it and send it to your hook.

    We’ve already asked our developers to look into it and I think we should be able to provide you with solution for this but I’d appreciate some patience as our developers are dealing with a lot of complex tasks on daily basis.

    We’ll update you here with more information soon.

    Best regards,
    Adam

  • Adam
    • Support Gorilla

    Hi MC-Net Services

    Thanks for response!

    I checked the other ticket and I understand that they are related in terms of “functionality” but technically-wise, they are related to different aspects of plugin code and need separate solution.

    I think it’d be better to keep them separate for now and we can then check if both solution can be in some way “merged” in terms of code later on, once both solutions are already tested and proven to work.

    We’ll keep you update in both tickets.

    Best regards,
    Adam

  • Prashant
    • Staff

    Hi MC-Net Services

    I hope you are doing well.

    We have worked on your request and found a solution. Please add a must-use plugin to your site’s wp-content/mu-plugins folder like this https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins, then add the following code to the plugin’s php file:

    add_action( 'forminator_form_after_save_entry', 'wpmudev_convert_submitted_data_json', 10, 2 );
    function wpmudev_convert_submitted_data_json( $module_id, $response ){
    	if( $module_id != 2171 ){
    		return;
    	}
    
    	if ( $response && is_array( $response ) ) {
    		if ( $response['success'] ) {
    			$data = array();
    			$submit_data = Forminator_CForm_Front_Action::$info['field_data_array'];
    			if( is_array( $submit_data ) ){
    				foreach( $submit_data as $key => $value ){
    					if( isset( $value['name'] ) ){
    						$data[$value['name']] = $value['value'];
    					}
    				}
    			}
    
    			if( is_array( $data ) && $data ) {
    				$jsonEncodedData = json_encode($data);
    				$curl = curl_init();
    				$opts = array(
    					CURLOPT_URL             => 'Your_Webhook_URL',
    					CURLOPT_RETURNTRANSFER  => true,
    					CURLOPT_CUSTOMREQUEST   => 'POST',
    					CURLOPT_POST            => 1,
    					CURLOPT_POSTFIELDS      => $jsonEncodedData,
    					CURLOPT_HTTPHEADER  => array('Content-Type: application/json','Content-Length: ' . strlen($jsonEncodedData))                                                                       
    				);
    				// Set curl options
    				curl_setopt_array($curl, $opts);
    
    				// Get the results
    				$result = curl_exec($curl);
    
    				// Close resource
    				curl_close($curl);
    			}
    		}
    	}
    }

    Note: In the code please change the form ID from 2171 to your form’s ID and Your_Webhook_URL with your webhook URL. Also, the curl code is just an example of how to send the data to an external webhook so please check if you need to do any modifications.

    We recommend to test this on the dev/staging version first before putting it on the live site.

    Hope it will solve your problem.

    Kind Regards
    Prashant