Support » Plugin: Contact Form DB » How to save data to a different table?

Viewing 5 replies - 1 through 5 (of 5 total)
  • my goal is to save the data to an existing table, where each submission is one row and each field is a column.
    where can i do that?

    Plugin Author Michael Simpson


    Not out of the box. If you create a filter according to this post, you could put statements in that function to insert the form data into a different DB. But you have to write the code to do it.

    me and code are friends, so no problem there.
    in the ‘cfdb_form_data’ function i can parse my data to my liking and save it to the cf7db predefined table, i can also add saving to my own table, but i cannot replace the table.
    now the data is being saved in both tables.

    if this is the only way, i rather go with another – ‘wpcf7_mail_sent‘:

    add_action( 'wpcf7_mail_sent', "wpcf7_parse_after_send");
    function wpcf7_parse_after_send($cfdata){
    	global $wpdb;
    	$data = array(
    		'new_name' => $cfdata->posted_data['name'],
    		'new_desc' => $cfdata->posted_data['desc']
    	$wpdb->insert($wpdb->prefix.'my_own_table', $data);

    am i right??

    Plugin Author Michael Simpson


    You are right that you would be saving it to both places.

    You can hook into the CF7 hook like you show above or you can use the hook I provide in the link I cited above to define a function that inserts into your table. Both will work.

    If you use the CF7 hook, then you don’t need the CFDB plugin at all (essentially you wrote your own!) But if you use the CF7 hook, it will only work with CF7. If you use the CFDB hook, it will work with all the front-ends forms that CFDB integrates with. And you get the data in both tables (don’t know if you consider that good or bad…but it let you use the CFDB short codes which pull data from the CFDB table, not your table)

    For any one else reading, I think it worth mentioning that you can always create a View on the CFDB table to make it look like a regular table with columns for each of the form entries.

    essentially you wrote your own!

    wow, you have enlightened me, i didn’t even realized that i was doing that.
    tnx for the help, keep up the good work.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to save data to a different table?’ is closed to new replies.