Skip to content

Instantly share code, notes, and snippets.

@chrisegg
Created December 18, 2025 03:43
Show Gist options
  • Select an option

  • Save chrisegg/e83999289f641fcf400d9e3a0a36c9ea to your computer and use it in GitHub Desktop.

Select an option

Save chrisegg/e83999289f641fcf400d9e3a0a36c9ea to your computer and use it in GitHub Desktop.
Replaces Gravity Forms post content with a real Gutenberg Table block, dynamically populated using form field values via merge tags.
<?php
/**
* Title: Gravity Forms → Gutenberg Table Block Output
* Description: Replaces Gravity Forms post content with a real Gutenberg Table block,
* dynamically populated using form field values via merge tags.
* Author: Chris Eggleston
*
* How to Use:
* 1. Update the form ID check to match your target form.
* 2. Replace the merge tags ({Name:1}, {Email:2}, etc.) with your own field labels and IDs.
* 3. Add this snippet to a plugin, MU-plugin, or your theme’s functions.php file.
* 4. Ensure the Gravity Forms Post Fields are configured to create a post.
*
* Result:
* - The post is saved with a native Gutenberg Table block (not a Classic block).
* - The table is fully editable in the block editor after submission.
*/
add_filter( 'gform_post_data', function ( $post_data, $form, $entry ) {
// Only target a specific form
if ( $form['id'] !== 1 ) {
return $post_data;
}
$table_template = <<<HTML
<!-- wp:table -->
<figure class="wp-block-table">
<table>
<thead>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name</td>
<td>{Name:1}</td>
</tr>
<tr>
<td>Email</td>
<td>{Email:2}</td>
</tr>
<tr>
<td>Company</td>
<td>{Company:3}</td>
</tr>
</tbody>
</table>
</figure>
<!-- /wp:table -->
HTML;
// Replace merge tags with submitted values
$table_block = GFCommon::replace_variables(
$table_template,
$form,
$entry,
false,
true,
false,
'html'
);
// Set post content to the Gutenberg Table block
$post_data['post_content'] = $table_block;
return $post_data;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment