Download Log in

15. Submission Data Structure

Developer Guide

Database Row

Each submission is stored as a row in wp_formforge_submissions. The data column contains a JSON-encoded string of all submitted field values.

Decoded data Field

Each key in the decoded data object is the field ID. Each value has label, value, and type:

json
{
  "field_1": {
    "label": "Full Name",
    "value": "John Doe",
    "type": "text"
  },
  "field_2": {
    "label": "Email",
    "value": "[email protected]",
    "type": "email"
  }
}

Value Formats by Field Type

Field TypeValue FormatExample
text, email, phone, urlPlain string"John Doe"
textareaString (may contain newlines)"Line 1nLine 2"
numberNumeric string"42"
select, radioSelected option value"sales"
checkbox (single)"1" or """1"
checkbox (multiple)JSON array string"["option1","option2"]"
dateISO date string"2025-03-15"
ratingNumeric string (1-N)"4"
file_uploadURL to uploaded file"https://example.com/.../resume.pdf"
map_addressJSON-encoded location"{"address":"...","lat":"40.7"}"
paymentPaymentIntent ID"pi_3N1234567890"
repeaterJSON-encoded array"[{"name":"Row 1"}]"

Stored values preserve enough structure for integrations, but user-facing surfaces should not print the raw storage form. Use FORMFORGE_Value_Formatter::submission_display_fields() or FORMFORGE_Value_Formatter::text() when rendering emails, Slack/Discord/Telegram messages, CSV/PDF rows, submission modals, or post-submission content. The formatter converts scalar checkbox values to readable labels, groups repeater rows, formats date/calendar values with the WordPress site format, masks passwords, skips empty hidden/system fields, de-duplicates map coordinates, and appends Payment status / amount / date / ID rows from _payment.

Querying Submissions in PHP

php
global $wpdb;
$table = $wpdb->prefix . 'formforge_submissions';

$submissions = $wpdb->get_results( $wpdb->prepare(
    "SELECT * FROM {$table} WHERE form_id = %d ORDER BY created_at DESC LIMIT 100",
    42
) );

foreach ( $submissions as $sub ) {
    $data = json_decode( $sub->data, true );
    $name  = $data['field_1']['value'] ?? '';
    $email = $data['field_2']['value'] ?? '';
    echo "Submission #{$sub->id}: {$name} ({$email})n";
}

Exporting Submissions as CSV

php
function export_submissions_csv( $form_id ) {
    global $wpdb;
    $table = $wpdb->prefix . 'formforge_submissions';
    $rows = $wpdb->get_results( $wpdb->prepare(
        "SELECT * FROM {$table} WHERE form_id = %d AND status = 'new' ORDER BY created_at ASC",
        $form_id
    ) );

    if ( empty( $rows ) ) return '';

    $output = fopen( 'php://temp', 'r+' );
    $first_data = json_decode( $rows[0]->data, true );
    $headers = [ 'ID', 'Date' ];
    foreach ( $first_data as $field ) {
        $headers[] = $field['label'];
    }
    fputcsv( $output, $headers );

    foreach ( $rows as $row ) {
        $data = json_decode( $row->data, true );
        $line = [ $row->id, $row->created_at ];
        foreach ( $data as $field ) {
            $val = is_array( $field['value'] ) ? implode( ', ', $field['value'] ) : $field['value'];
            $line[] = $val;
        }
        fputcsv( $output, $line );
    }

    rewind( $output );
    $csv = stream_get_contents( $output );
    fclose( $output );
    return $csv;
}

Forge AI Assistant Online

Hi! I'm the Form Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs