Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feliciaceballos/3b0131df19fb46146650a39a5bd66f2a to your computer and use it in GitHub Desktop.
Save feliciaceballos/3b0131df19fb46146650a39a5bd66f2a to your computer and use it in GitHub Desktop.
Create the WPMU DEV Forminator Recent Submissions Dashboard Widget, Formatting Submissions
<?php
/**
* Render Form Submissions table on html widget
*
* @param Forminator_Custom_Form_Model $form
* @param Forminator_Form_Entry_Model[] $entries
*/
public function render_form_submissions( $form, $entries ) {
$field_labels = array();
// Get fields labels
if ( ! is_null( $form ) ) {
if ( is_array( $form->fields ) ) {
foreach ( $form->fields as $field ) {
/** @var Forminator_Form_Field_Model $field */
$field_labels[ $field->slug ] = $field->get_label_for_entry();
}
}
}
?>
<h3><?php echo( is_null( $form ) ? esc_html( __( 'Not Found' ) ) : esc_html( $form->name ) ); ?></h3>
<table class="widefat fixed" cellspacing="0">
<thead>
<tr>
<th id="id" class="manage-column id" scope="col"><?php esc_html_e( 'ID' ); ?></th>
<th id="entry" class="manage-column entry" scope="col"><?php esc_html_e( 'Entry' ); ?></th>
<th id="date" class="manage-column date" scope="col"><?php esc_html_e( 'Time' ); ?></th>
</tr>
</thead>
<tbody>
<?php
// set limit
$limit = count( $entries );
if ( $limit > $this->limit ) {
$limit = $this->limit;
}
?>
<?php for ( $i = 0; $i < $limit; $i ++ ) : ?>
<?php
/** @var Forminator_Form_Entry_Model $entry */
$entry = $entries[ $i ];
?>
<tr class="<?php echo( ( $i % 2 ) ? 'alternate' : '' ); ?>">
<td class="id"><?php echo esc_html( $entry->entry_id ); ?></td>
<td class="entry">
<ul>
<?php foreach ( $entry->meta_data as $field_id => $meta ) : ?>
<?php if ( isset( $field_labels[ $field_id ] ) ) : // only display entry with field label exist ?>
<?php $field_value = $meta['value']; ?>
<li>
<?php echo esc_html( $field_labels[ $field_id ] ); ?> :
<?php if ( is_array( $field_value ) ) : // show key too when its array value (multiname, multiple choices) ?>
<?php foreach ( $field_value as $key => $val ) : ?>
<?php echo esc_html( $key ); ?>: <?php echo esc_html( $val ); ?><br/>
<?php endforeach; ?>
<?php else : ?>
<?php echo esc_html( $field_value ); ?>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</td>
<td class="date">
<?php echo esc_html( $entry->time_created ); ?>
</td>
</tr>
<?php endfor; ?>
</tbody>
<tfoot>
<tr>
<th id="id" class="manage-column id" scope="col"><?php esc_html_e( 'ID' ); ?></th>
<th id="entry" class="manage-column entry" scope="col"><?php esc_html_e( 'Entry' ); ?></th>
<th id="date" class="manage-column date" scope="col"><?php esc_html_e( 'Time' ); ?></th>
</tr>
</tfoot>
</table>
<?php if ( ! is_null( $form ) ) : ?>
<ul class="">
<li class="all">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=forminator-entries&form_type=forminator_forms&form_id=' . $form->id ) ); ?>"><?php esc_html_e( 'View Submissions' ); ?>
<span class="count">(<span class="all-count"><?php echo esc_html( count( $entries ) ); ?></span>)
</span>
</a>
</li>
</ul>
<?php endif; ?>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment