Custom Fields
Re-Envisioned
Support MB Custom Table MB Custom Table And Gravity Forms

  • Creator
    Topic
  • #17700
    Resolved TopDog
    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #17715
    Anh 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
    TopDog
    Participant

    Thanks for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
grid gear info copy caret-up caret-down trash