简体   繁体   中英

Insert into database from contact form

I'm trying to insert data from a contact form (CF7) into two different table I'm pretty sure my code is correct, but still nothing

Here's the code

 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"
));
 }
}

I know there's another plugin that does the job, but I'd rather do it my way

Thanks, Jeremie.

Steps to perform:

  1. Turn on WP Debug and see if you get some obvious error or warning

  2. Check if the function my_conversion is called eg write

    echo "I am called"; die;

  3. Most probably the wpdb->insert is not working

Try the following:

var_dump( $wpdb->last_query );

or

$wpdb->print_error()

As you are most probably doin all this within an ajax request make sure to write the debugging results into a logfile or make sure you can see the results on your screen or within your console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM