I'm adapting the code to retrieve information from the Elementor form. I've referred to the documentation, and I have an example code snippet.
function send_custom_webhook( $record, $handler ) {
$form_name = $record->get_form_settings( 'form_name' );
// Replace MY_FORM_NAME with the name you gave your form
if ( 'MY_FORM_NAME' !== $form_name ) {
return;
}
$raw_fields = $record->get( 'fields' );
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}
wp_remote_post(
'https://api.example.com/',
[
'body' => $fields,
]
);
}
add_action( 'elementor_pro/forms/new_record', 'send_custom_webhook', 10, 2 );
And here is the code from the platform that I'm attempting "Wolkvox", I've referred to the documentation, and I have an example code snippet.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'[{
"customer_name": "name",
"customer_id": "customerID",
"opt1": "tel1",
}]',
CURLOPT_HTTPHEADER => array(
'wolkvox-token: '
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}
The following is the output when I integrate both code samples
function send_to_external_api( $record, $handler ) {
$form_name = $record->get_form_settings( 'Testing' );
if ( 'Testing' !== $form_name ) {
return;
}
$raw_fields = $record->get( 'fields' );
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}
$data = json_encode([
"customer_name" => $fields['name'],
"customer_id" => $fields['customerID'],
"tel1" => $fields['tel1'],
]);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
'wolkvox-token: ',
'Content-Type: application/json',
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}
However, it's not sending any information to the API. Upon checking the Wolkvox platform, there doesn't appear to be any added information.
I have replaced the corresponding information in both the CURLOPT_URL and the token.
I would appreciate any guidance regarding what I might be doing wrong or why the information isn't being sent.