1. Home
  2. Snippets
  3. Display form entries

Display form entries

Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

For extra guidance, please see WPBeginner's tutorial on adding custom code.

Dismiss

WPForms is set up with security in mind, so by default only WordPress admin users will be able to see entry data.

If you’d like to display entries on the front-end of your site, though, you can accomplish this with the custom shortcode below. This code doesn’t require any changes, and is ready to be added to your site.

/**
 * Custom shortcode to display form entries in a table.
 *
 * Usage [wpforms_entries_table id="FORMID"]
 *
 * @param array $atts
 */
function wpf_dev_entries_table( $atts ) {
	$atts = shortcode_atts( array(
		'id' => ''
	), $atts );
	if ( empty( $atts['id'] ) || !function_exists( 'wpforms' ) ) {
		return;
	}
	$form = wpforms()->form->get( absint( $atts['id'] ) );
	if ( empty( $form ) ) {
		return;
	}
	$form_data = !empty( $form->post_content ) ? wpforms_decode( $form->post_content ) : '';
	$entries   = wpforms()->entry->get_entries( array( 'form_id' => absint( $atts['id'] ), 'number' => -1 ) );
	$disallow  = apply_filters( 'wpforms_frontend_entries_table_disallow', array( 'divider', 'html', 'pagebreak', 'captcha' ) );
	$ids       = array();
	ob_start();
	echo '<table class="wpforms-frontend-entries">';
		echo '<thead><tr>';
			foreach( $form_data['fields'] as $field ) {
				if ( !in_array( $field['type'], $disallow ) ) {
					$ids[] = $field['id'];
					echo '<th>' . sanitize_text_field( $field['label'] ) . '</th>';
				}
			}
		echo '</tr></thead>';
		echo '<tbody>';
			foreach( $entries as $entry ) {
				echo '<tr>';
				$fields = wpforms_decode( $entry->fields );
				foreach( $fields as $field ) {
					if ( in_array( $field['id'], $ids ) ) {
						echo '<td>' . apply_filters( 'wpforms_html_field_value', wp_strip_all_tags( $field['value'] ), $field, $form_data, 'entry-frontend-table' );
					}
				}
				echo '</tr>';
			}
		echo '</tbody>';
	echo '</table>';
	$output = ob_get_clean();
	return $output;
}
add_shortcode( 'wpforms_entries_table', 'wpf_dev_entries_table' );

To display entries in a page or post, you’ll need to use the following shortcode, where ‘FORMID’ is replaced with the form’s ID number:

[wpforms_entries_table id="FORMID"]

A form’s ID number can be found by going to WPForms » All Forms and looking to the number in the shortcode for each form.

How to locate a forms ID

For this example, we’ll modify the shortcode to use the form with an ID of 51:

[wpforms_entries_table id="51"]

The styling of your entry table will vary depending on your theme’s styles. Here’s an example from the Twentyseventeen default WordPress theme:

Entries table

Updated on October 3, 2018

Was this article helpful?