Frominator send entry to brevo
-
Hello i try to send entry to brevo (no integration dommage)
but my custom code doesn’t works … i don’t understand why
add_action(‘forminator_form_after_save_entry’, function($entry, $form) {
// Configuration
$form_id = 32; // My FORM
$api_key = ‘MYAPIKEY’; // À remplacer
$list_id = 36; //MY brevo list// Récupère les données du formulaire
$meta_data = $entry->meta_data;
error_log('Forminator Entry Meta Data (Debug): ' . print_r($meta_data, true));
// Vérifie si la checkbox est cochée
$checkbox_checked = isset($meta_data['checkbox-1']) && !empty($meta_data['checkbox-1']);
if (!$checkbox_checked) {
error_log('Brevo: Checkbox non cochée, abandon');
return;
}
// Extraction et sanitisation des champs CORRIGÉS
$email = isset($meta_data['email-1']) ? sanitize_email($meta_data['email-1']) : '';
$prenom = isset($meta_data['name-1']) ? sanitize_text_field($meta_data['name-1']) : '';
$nom = isset($meta_data['name-2']) ? sanitize_text_field($meta_data['name-2']) : '';
if (!is_email($email)) {
error_log('Brevo: Email invalide - ' . $email);
return;
}
error_log('Brevo: Traitement - Email: ' . $email . ', Prénom: ' . $prenom . ', Nom: ' . $nom);
// Prépare le payload pour l'API Brevo
$payload = array(
'email' => $email,
'firstName' => $prenom,
'lastName' => $nom,
'listIds' => array((int)$list_id),
'updateEnabled' => true, // Mettre à jour si le contact existe
);
// Appel API Brevo
$response = wp_remote_post('https://api.brevo.com/v3/contacts', array(
'method' => 'POST',
'headers' => array(
'api-key' => $api_key,
'Content-Type' => 'application/json',
),
'body' => wp_json_encode($payload),
'timeout' => 15,
));
// Traitement de la réponse
if (is_wp_error($response)) {
error_log('Brevo API Error: ' . $response->get_error_message());
return;
}
$status_code = wp_remote_retrieve_response_code($response);
$response_body = wp_remote_retrieve_body($response);
if ($status_code >= 200 && $status_code < 300) {
// Succès
error_log('✅ Brevo: Contact ajouté/mis à jour - ' . $email);
} else {
// Erreur API
error_log('❌ Brevo API Error (' . $status_code . '): ' . $response_body);
}}, 10, 2);
But i don’t understand nothing was sended to brevo and i didn’t have anything in wplog ….
thanks for any help
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.