Skip to content

Commit 9624fff

Browse files
author
Antti Kuosmanen
committed
Add a proper single submission view
1 parent ad2dc73 commit 9624fff

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

classes/class-cpt-wplf-submission.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,57 @@ function filter_by_form( $query ) {
147147

148148
return $query;
149149
}
150+
151+
/**
152+
* Add meta box to show fields in form
153+
*/
154+
function add_meta_boxes_cpt() {
155+
// Shortcode meta box
156+
add_meta_box(
157+
'wplf-shortcode',
158+
__( 'Submission', 'wp-libre-form' ),
159+
array( $this, 'metabox_submission' ),
160+
'wplf-submission',
161+
'normal',
162+
'high'
163+
);
164+
}
165+
166+
/**
167+
* The submission metabox callback
168+
*/
169+
function metabox_submission() {
170+
global $post;
171+
$postmeta = get_post_meta( $post->ID );
172+
$fields = array_keys( $postmeta );
173+
?>
174+
<p>
175+
<table class="wp-list-table widefat striped">
176+
<thead>
177+
<tr>
178+
<th><strong><?php _e( 'Field', 'wp-libre-form' ); ?></strong></th>
179+
<th><strong><?php _e( 'Value', 'wp-libre-form' ); ?></strong></th>
180+
</tr>
181+
</thead>
182+
<tbody>
183+
<?php foreach( $fields as $field ) : ?>
184+
<?php if( '_' != $field[0] ) : ?>
185+
<?php $value = $postmeta[ $field ][0]; ?>
186+
<tr>
187+
<th><strong><?php echo $field; ?></strong></th>
188+
<?php if( strlen( $value ) > 60 ) : ?>
189+
<td><textarea style="width:100%" readonly><?php echo $value; ?></textarea></td>
190+
<?php else : ?>
191+
<td><input style="width:100%" type="text" value="<?php echo $value; ?>" readonly></td>
192+
<?php endif; ?>
193+
</tr>
194+
<?php endif; ?>
195+
<?php endforeach; ?>
196+
</tbody>
197+
</table>
198+
</p>
199+
<?php
200+
}
150201
}
151202

152203
endif;

inc/wplf-form-actions.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ function wplf_send_email_copy( $return ) {
2020
$subject = wp_sprintf( __('New submission from %s', 'wp-libre-form'), $referrer );
2121
$content = wp_sprintf( __('Form "%s" (ID %d) was submitted with values below: ', 'wp-libre-form'), $form_title, $form_id ) . "\n\n";
2222
foreach( $_POST as $key => $value ) {
23+
if( '_' !== $key[0] ) {
24+
continue;
25+
}
2326
if( $key === 'referrer' ) {
2427
$key = __( 'referrer', 'wp-libre-form' );
2528
}
26-
if( $key != '_form_id' ) {
27-
$content .= esc_html( $key ) . ': ' . esc_html( print_r( $value, true ) ) . "\n";
28-
}
29+
30+
$content .= esc_html( $key ) . ': ' . esc_html( print_r( $value, true ) ) . "\n";
2931
}
3032
wp_mail( $to, $subject, $content );
3133
}

0 commit comments

Comments
 (0)