• I have read and tried many forum topics about this subject, but I can retrieve the value of a form field.

    This code works flawless, except it does not enter any value for the variable $emailadres

    function wpcf7_modify_this(&$wpcf7_data) {
    global $wpdb;
    $DB_NAME = 'perspexocmsnl';
    $DB_USER = 'perspexocmsn';
    $DB_PASSWORD = 'xxxxxxx';
    $DB_HOST = 'localhost';
    
    $newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
    $emailadres = $wpcf7_data->posted_data['your-email'];
    $newdb ->query("insert into px_mailinglist (emailadres) values ('$emailadres')");
    
    }
    add_action("wpcf7_before_send_mail", "wpcf7_modify_this");

    I also tried the wpdb variant, but with the same result:
    a row is inserted in the database but no value for the field emailadres is inserted.

    Is there anybody who can help me with this?

    Thanks a lot.

Viewing 1 replies (of 1 total)
  • Turns out Contact Form 7 has a new way of retrieving the posted data. You replace

    $emailadres = $wpcf7_data->posted_data['your-email'];

    with

    $submission = WPCF7_Submission::get_instance();
    if($submission) {
        $data = $submission->get_posted_data();
        $emailadres = $data['your-email'];
        $wpdb->insert(...
    }

    I found that out by looking through the code of the Contact Form DB plugin which might be a great general purpose plugin for the kind of thing you’re doing.

Viewing 1 replies (of 1 total)

The topic ‘Contact form 7 insert value into database’ is closed to new replies.