我为 Elementor Pro 表单创建了一个 WordPress 插件,它将捕获表单提交数据并将该数据发送到其他数据库,然后继续并将响应保存在 elementor 表单提交中。
现在的问题是,当提交表单时,它提交得很好,但表单下方显示的是解析错误,而不是谢谢!成功消息。我还在表单小部件中启用了自定义消息选项。
这是代码插件代码
<?php
/**
* Plugin Name: Elementor API Capture
* Description: Custom plugin to capture Elementor form submissions and send to API.
* Version: 1.1
*/
// Hook into Elementor form submission
add_action('wp_ajax_elementor_pro_forms_send_form', 'capture_elementor_form_submission');
add_action('wp_ajax_nopriv_elementor_pro_forms_send_form', 'capture_elementor_form_submission');
function capture_elementor_form_submission()
{
// Access the form data submitted by Elementor
$post_data = $_POST['form_fields'];
// print_r($post_data);die;
/*
* 🔺 Your API Request Logic Here 🔺
* Prepare data to send to the API
*/
$siteName = $_SERVER['SERVER_NAME'];
// echo $siteName;
$post_data['source'] = $siteName;
// print_r($post_data);die;
// Make the API request
$response = wp_remote_post('api-end-point', array(
'body' => $post_data
// 'headers' => array('Content-Type' => 'application/json'),
));
// print_r($response);die;
// Check for API request success
if (is_wp_error($response)) {
// Handle API request error
echo 'API Request Error: ' . $response->get_error_message();
} else {
// API request successful
$api_response = json_decode(wp_remote_retrieve_body($response), true);
echo 'API Response: ' . json_encode($api_response);
}
/*
* 🔺 END HERE 🔺
*/
// Continue with Elementor's form submission handling
include_once(plugin_dir_path(__FILE__) . 'elementor-pro/modules/forms/classes/ajax-handler.php');
$ajax_handler = new ElementorPro\Modules\Forms\Classes\Ajax_Handler();
$ajax_handler->ajax_send_form();
// Make sure to exit to prevent further processing of Elementor's form submission
exit;
}
我为 Elementor Pro 表单创建了一个 WordPress 插件,它将捕获表单提交数据并将该数据发送到其他数据库,然后继续并将响应保存在 elementor 表单提交中。
现在,当提交表单时,表单已提交,数据也被推送到数据库,但在前端,而不是在表单下方显示成功消息,而是显示解析错误。
我在 Elementor Pro Form Widget 中启用了自定义表单消息选项。
有什么解决办法吗? a mi me sucede lo Mismo y no sé qué hacer