首页 > 解决方案 > 联系表格 7 不显示成功消息?

问题描述

我已经复制了关于联系表格 7 wordpress 的代码,目前数据已经成功发送到外部数据库,但是消息成功几乎没有显示以及我已经移动到感谢页面。谢谢

function wpcf7_send_to_external ( $cf7 ) {

//external db details
$username = 'username';
$password = 'pass';
$database = 'database';
$host = 'myip';


//create new wpdb instance
$mydb = new wpdb($username, $password, $database, $host);


        $cf7 = WPCF7_ContactForm::get_current();
        $submission = WPCF7_Submission::get_instance();
        $data = $submission->get_posted_data();


        $field1 = $data["name"];
        $field2 = $data["semail"];
        $field3 = $data["phone"];
        $field4 = $data["nhu"];


        //insert into external db
        $mydb->insert( 

            'customer',

            array( 
                'name' => $field1, 
                'email' => $field2,
                'phone' => $field3,
                'content' => $field4
            ),

            array( 
                '%s','%s','%s','%s'
            ) 
        );

}

add_action("wpcf7_before_send_mail", "wpcf7_send_to_external");

标签: phpwordpresscontact-form-7

解决方案


这看起来像是从 JavaScript 文件中调用的,您可以在那里执行 console.log。

console.log("Success message!");

如果您需要 PHP 文件中的数据,您可以通过回显将其发回。(可以作为对 HTTP 请求的响应进行访问。

echo "some data: $variable";

推荐阅读