2015-08-08 43 views
0

我試圖從一個接觸的形式(CF7)數據插入到兩個不同的表 我敢肯定我的代碼是正確的,但仍沒有插入從接觸形式的數據庫

下面的代碼

remove_all_filters ('wpcf7_before_send_mail'); 
add_action('wpcf7_before_send_mail', 'my_conversion'); 

function my_conversion($cf7) 
{ 
    $email = $cf7->posted_data["email"]; 
    $name = $cf7->posted_data["lastname"]; 
    $tel = $cf7->posted_data["cf_3"]; 
    $fonction = $cf7->posted_data["cf_1"]; 
    $entreprise = $cf7->posted_data["cf_2"]; 
    $newsletter = $cf7->posted_data["newsletter"]; 

    insert($email, $name, $tel, $fonction,$entreprise,$newsletter); 
} 

function insert($email, $name, $tel, $fonction,$entreprise,$newsletter) 
{ 
    global $wpdb; 
    $wpdb->insert("wp_wysija_user", array(
    "user_id" => NULL, 
    "wpuser_id" =>"0", 
    "email" => $email, 
    "firstname" => "", 
    "lastname" => $name, 
    "ffonc" => $fonction, 
    "fent" => $entreprise, 
    "ftel" => $tel, 
    "ip" => "0", 
    "confirmed_ip" => NULL, 
    "confirmed_at" => NULL, 
    "last_opened" => NULL, 
    "last_clicked" => NULL, 
    "keyuser" => NULL, 
    "created_at" => "", 
    "status" => "0", 
    "domain" => "" 
)); 

if($newsletter == "oui") 
{ 

$wpdb->insert("wp_wysija_user_list", array(
"list" => "3", 
"user_id" => NULL, 
"sub_date" => "1430666348", 
"unsub_date" => "0" 
)); 
} 
} 

我知道有,沒有工作的另一個插件,但我寧願我的方式去做

感謝, 雷米。

回答

0

步驟來執行:

  1. 打開WP調試,看看你得到一些明顯的錯誤或警告

  2. 檢查功能my_conversion被稱爲例如寫

    回聲「我叫」;死;

  3. 最有可能的wpdb->插入不工作

嘗試以下操作:

var_dump($wpdb->last_query); 

$wpdb->print_error() 

因爲你是最有可能doin al l在ajax請求中,請確保將調試結果寫入日誌文件中,或確保可以在屏幕上或控制檯中查看結果。

+0

你是對的,這是插入功能不起作用 使用var_dump它顯示字段是空的,但我不明白爲什麼 是否有什麼與CF7形式? –

+0

可能有些值是錯誤的或被數據庫拒絕。嘗試消毒你的輸入。 https://codex.wordpress.org/Class_Reference/wpdb#INSERT_rows – Blackbam