• It seems wpcf7_before_send_mail doesn’t get sent the special tags?

    Am using the below code to save form data to MySQL, and only the name & email entries are stored in the database; the extended tags (site name & url, ip, etc.) are null.

    /* TBD save application data back to database */
    function save_application_form( $cf7 ) {
    	// form data
    	$SITENAME = $cf7->posted_data["_post_title"];
    	$SITEURL = $cf7->posted_data["_post_url"];
    	$NAMEFIRST = $cf7->posted_data["applicant-name-first"];
    	$NAMEFAMILY = $cf7->posted_data["applicant-name-family"];
    	$EMAIL = $cf7->posted_data["applicant-email"];
    	// additional data
    	$IPADDRESS = $cf7->posted_data["_remote_ip"];
    	$DATEAPPLY = $cf7->posted_data["_date"];
    	$TIMEAPPLY = $cf7->posted_data["_time"];
    
    	$sql = "INSERT INTO somedbase.sometable (
    		application_ID,
    		site_name,
    		site_url,
    		applicant_name_first,
    		applicant_name_family,
    		applicant_email,
    		applicant_ip_address,
    		applicant_date_apply,
    		applicant_time_apply
    	)
    	VALUES (
    		'NULL',
    		'$SITENAME',
    		'$SITEURL',
    		'$NAMEFIRST',
    		'$NAMEFAMILY',
    		'$EMAIL',
    		'$IPADDRESS',
    		'$DATEAPPLY',
    		'$TIMEAPPLY'
    	);";
    	mysql_query($sql);
    }
    add_action( 'wpcf7_before_send_mail', 'save_application_form' );

    [adding: for those looking for a simple way to save CF7 form data to MySQL, the above code works. You’ll want to replace somedbase & sometable with your site’s mysql info, next add sometable to your database (with the desired keys structure), then just add the above code to functions.php! Enjoy!]

    http://wordpress.org/extend/plugins/contact-form-7/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Casemon

    (@casemon)

    Anyone?

    $cf7->posted_data array doesn’t contain the values from the special mail tags. See wpcf7_special_mail_tag() and wpcf7_special_mail_tag_for_post_data() in the inludes/classes.php to see how you can take those values.

    Thread Starter Casemon

    (@casemon)

    Hmm can you provide more details?

    Not sure what I’m looking for here, much less how to leverage what I find if I do find what I don’t know what I’m looking for 😉

    Casemon: I tried adding your code above to the functions.php of my theme to add values to a MySQL db but it does not work – I cannot verify that the wpcf7_before_send_mail hook is active not can I see where the $cf7 array is assembled in the plug in – any help you can give would be great. Happy to pool my findings on declaring the extended tags to track those too.

    Thanks

    Thread Starter Casemon

    (@casemon)

    @titusbicknell
    post your adaptation of the code and we’ll go from there!

    Hey guys!

    I’m trying to get the save in database working…

    In my theme’s function.php I added:

    function save_application_form($cf7) {
    global $wpdb;
    if(isset($cf7->posted_data[“your-message”])) {
    $table_name = “form_contact”;
    $wpdb->insert($table_name, array(‘name’ => $cf7->posted_data[“your-name”],’e-mail’ => $cf7->posted_data[“your-email”],’subject’ => $cf7->posted_data[“your-subject”],’message’ => $cf7->posted_data[“your-message”]));
    }
    }

    <?php add_action( ‘wpcf7_before_send_mail’, ‘save_application_form’);?>

    —-
    Deleted my question, it is working like a charm. Feel free to use 🙂

    all but given up on contact form 7 saving to a db but one last try:

    chrillea’s code does not work for me: if i copy it into the funcitons.php file the site fails to laod at all, if I make it a plug in file nothing shows in the db table when I test the form, however this works:

    function cf72db ($cf7) {
    
    $cf7_name = $cf7->posted_data["your-name"];
    $cf7_email = $cf7->posted_data["your-email"];
    $cf7_id = $cf7->id;
    $sql = "INSERT INTO wp30.cf7_data (
    Name,
    Email,
    FormID
    ) VALUES (
    '$cf7_name',
    '$cf7_email',
    '$cf7_id'
    )";
    mysql_query($sql);
    }
    
    add_action( 'wpcf7_before_send_mail', 'cf72db' );

    not as elegant but working – any clues why the $wpdb insert function would not work?

    hi,

    I am about to do something similar, did you include $wpdb in your function??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Contact Form 7] Special tags not sent to wpcf7_before_send_mail for saving to MySQL?’ is closed to new replies.