0

I want to save the form to a custom table in my WP database. The email should still be sent.

I have read this post and came up with the below code which is currently in my theme's function.php file:

add_action( 'wpcf7_before_send_mail', 'process_form' );

function process_form( $cf7 )
{
    global $wpdb;
    if($cf7->posted_data['_wpcf7'] == 20) {
        $wpdb->insert('newsletter_signups',
            array(
                'name'=>$cf7->posted_data['name'],
                'email'=>$cf7->posted_data['email']
            )
        );
    }
}

If I take the insert out of the if-statement, and give it fixed values, it saves to the database. However it does not save to the table if I do as above. Now I'm assuming that it's because it's not receiving any data. I don't know how to debug the variable that it receives, as it's an ajax request. If I print_r($cf7) it doesn't show anything in my element inspector or on the network tab (in Chrome). So, I have 2 questions regarding this:

  1. How can I debug the variables passed here?
  2. How can I change this function so that it does my processing?

closed as off-topic by birgire, Pieter Goosen, Mark Kaplun, Johannes Pille, gmazzap Sep 28 '14 at 21:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – birgire, Pieter Goosen, Mark Kaplun, Johannes Pille, gmazzap
If this question can be reworded to fit the rules in the help center, please edit the question.

  • How is this not specific to wordpress? – Albert Sep 29 '14 at 5:06
2

Contact form 7 changed classes in 3.9 version. Now this is how it goes.

add_action( 'wpcf7_before_send_mail', 'process_form' );

function process_form( $cf7 ) {

    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }

    if( $cf7->id() == 20 ) {
        $wpdb->insert('newsletter_signups',
            array(
                'name' => $posted_data['name'],
                'email' => $posted_data['email']
            )
        );
    }
}

Read more about change here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.