Submit GF to New database


I am trying to connect and replicate gravity form table structure to a new database. So i currently created a new global $wpdb; ie: global $gravitydb in wp-config.php.

I can connect to this new database, and save data per form, to new table. ie

add_action("gform_after_submission_3", "input_fields", 10, 2);
function input_fields($entry, $form){
    global $gravitydb;

                    $entry["1"] = $_POST["name"];
                    $entry["2"] = $_POST["email"];

   $SQL = "INSERT INTO users ( userID, name, email) VALUES ( '', $_POST["name"] , $_POST["email"], '$purchase_date', '$order_number')";

The entries are inserted in the database, but my main question is how would i replicate the current gravity forms table structure to my new database and capture the entries like they are currently added to the current database. Would love to have separate entries for gravity form entries.

I guess the big question is WHY?

What was wrong with using Wordpress’ database?

hi @Parkbum, Thanks for getting back to me. Reason for this ask there are too many entries from the forms on the front end, so they would like to separate the 2 databases.

Well, hypothetically… If they are just hoping to save certain private data (credit cards, social security numbers, etc.) in a secure/different location, I would just just setup a new table on the new database, and then in an after_submission hook, instruct the website to save just that data with an entry/user/reference id and then destroy the duplicated data in the WordPress Database. You would then query that new database the old fashion way whenever you needed the “secure” data, but otherwise it wouldn’t mess up your day to day functionality.

It’s a bit of entry work, but that’s money on the clock!

Haven’t had a proper look at this issue, busy with other updates.

So i have a question / thought regarding this issue I have at hand. on the gform_after_submission submit function, can one not replicate the tables which gravity forms creates? my thinking regarding this and thoughts are as follows.

  • I copy the wp_gf_form table with all contents to new database.

  • I copy the wp_gf_form_meta table with all contents to new database.

  • On form submissions I get the form id and query the wp_gf_form table on the new database and get the ip address, thus inserting to the wp_gf_form_view table on the new database. table created from the current database

  • On submission i store the values from the form to wp_gf_entry_meta, where entry_id will be equal to wp_gf_entry id, and wp_gf_form_view id = and wp_gf_form_meta and wp_gf_entry_meta.entry_id

not sure if this would be the correct way of recreating the above to a new database.

another Q, how would i mark read and such actions in the cms should i manage to add the data by querying to the new database replicating the tables?

will look at this: maybe post to a controller on the site get the form data and write the save data script there…