Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shortcode to show current user entries for a specific form using [show_user_entries id="1"] where 1 is the form ID
<?php
/**
* Plugin Name: Quform Show User Entries
* Plugin URI: http://www.quform.com
* Description: Shortcode to show current user entries.
* Version: 1.1.0
* Author: ThemeCatcher
* Author URI: http://www.themecatcher.net
*/
add_shortcode('show_user_entries', function ($atts) {
$atts = shortcode_atts(array(
'id' => ''
), $atts);
$repository = Quform::getService('repository');
$formFactory = Quform::getService('formFactory');
$config = $repository->getConfig((int) $atts['id']);
if ( ! is_array($config)) {
return '<p>Form not found.</p>';
}
$output = '';
$form = $formFactory->create($config);
$entries = $repository->getEntries($form, array(
'order_by' => 'created_at',
'order' => 'ASC',
'limit' => 1000000,
'created_by' => get_current_user_id()
));
if (is_array($entries) && count($entries)) {
foreach ($entries as $entry) {
sue_set_form_values($form, $entry);
$output .= $form->replaceVariables('{all_form_data}', 'html');
}
} else {
$output .= '<p>No entries found.</p>';
}
return $output;
});
function sue_set_form_values(Quform_Form $form, array $entry)
{
$form->setValues(array(), true);
foreach ($entry as $key => $value) {
if (preg_match('/^element_\d+/', $key)) {
$elementId = (int) str_replace('element_', '', $key);
$form->setValueFromStorage($elementId, $entry[$key]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment