WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form DB
[resolved] How to save data to a different table? (6 posts)

  1. shemesh
    Member
    Posted 1 year ago #

    hi,
    simple question...
    how can i save the data to a different table?

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

  2. shemesh
    Member
    Posted 1 year ago #

    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?

  3. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  4. shemesh
    Member
    Posted 1 year ago #

    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??

  5. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  6. shemesh
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.