Quantcast
Channel: WordPress.org Forums » [Forminator Forms – Contact Form, Payment Form & Custom Form Builder] Support
Viewing all articles
Browse latest Browse all 1609

Sending Forminator Input Field Data to 3rd Party Application

$
0
0

Replies: 1

Hi,
I’m trying to send specific Forminator form input field data when the user submits. I’m using a hook forminator_form_after_save_entry but it was not working, even when I tried to log the Error handling it’s not showing.

add_action('forminator_form_after_save_entry', 'send_form_data_to_coperniq', 10, 2);

function send_form_data_to_coperniq($entry_id, $form_id) {
// Specify the Forminator form ID you want to target
$target_form_id = 3263;

if ($form_id != $target_form_id) {
return;
}

// Retrieve the submitted data
$entry = Forminator_API::get_entry($entry_id);
$data = $entry->get_fields();

// Map Forminator fields to Coperniq API fields
$payload = array(
'title' => $data['Contact Form Submission'] ?? '',
'address' => array($data['address-1'] ?? ''),
'trades' => array($data['trades'] ?? ''),
'primaryEmail' => $data['email-1'] ?? '',
'primaryPhone' => $data['phone-1'] ?? ''
// Add other fields as needed
);

// Send data to thirdy-party API
$response = wp_remote_post('https://sampledomain.com/v1/requests', array(
'headers' => array(
'Content-Type' => 'application/json',
'x-api-key' => 'xxxxx-xxxxxx-xxxxx' // Replace with your actual API key
),
'body' => json_encode($payload)
));

// Handle the response as needed
if (is_wp_error($response)) {
error_log('Third API request failed: ' . $response->get_error_message());
} else {
$response_body = wp_remote_retrieve_body($response);
// Process the response if necessary
}
}

Please take note that the API endpoint and API key in the provided script are just a dummy for security purposes.

Any help to submit successfully the Forminator data to the third-party application would be appreciated.

Thank you!
Mikee


Viewing all articles
Browse latest Browse all 1609

Trending Articles