MB Custom Table And Gravity Forms

Support MB Custom Table MB Custom Table And Gravity FormsResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17700
    TopDogTopDog
    Participant

    I want to create a custom database table using the MB Custom Table extension, however, I want to integrate Gravity Forms to do the following:

    1. Each gravity form that is published should create a new custom table with the column names corresponding to the gravity form fields.
    2. Form submissions should be written directly to the newly created custom table.

    Is this possible with the MB Custom Table extension?

    I'm specifically concerned about question 1 with how to create a new custom table for each new gravity form. Any assistance with code examples would be greatly appreciated.

    #17715
    Anh TranAnh Tran
    Keymaster

    Hi,

    #1. That can be done with GF hooks (after creating form) and MB Custom Table API. Something like

    add_action( 'gf_after_create_form', function() {
        $fields = gf_get_form_fields();
        $columns = [];
        foreach ( $fields as $field ) {
            $columns[$field] = 'TEXT NOT NULL';
        }
        MB_Custom_Table_API::create( 'my_custom_table', $columns );
    } );

    Please note that the GF action name and function should be corrected according to GF docs. This is just the pseudo-code, not an actual running code.

    #2. Similar to that, you should hook to GF after submission to insert a new row into the DB. We don't have a public API for that, but you can use $wpdb->insert() to do it.

    #17719
    TopDogTopDog
    Participant

    Thanks for the help!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.