Skip to content

Instantly share code, notes, and snippets.

@patrickfreitasdev
Last active March 9, 2024 02:27
Show Gist options
  • Save patrickfreitasdev/3ad0d0f4e13d3618cf8be210e8a48ac5 to your computer and use it in GitHub Desktop.
Save patrickfreitasdev/3ad0d0f4e13d3618cf8be210e8a48ac5 to your computer and use it in GitHub Desktop.
<?php
//Using this to protect the plugin
defined('ABSPATH') or die('What are you looking for?');
function wpmu_order_status_876(){
ob_start();
// Using this form to collect the data
$form_id = 182;
$entries = Forminator_API::get_entries( $form_id );
$currentUserId = get_current_user_id();
$submitedData = [];
$dataId = [];
// Collect the submission from the logged-in user based on the hidden-field user ID, update the hidden-1 if necessary https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#default-value
foreach($entries as $entrie){
$hiddenField = (int)$entrie->meta_data['hidden-1']['value'];
if($currentUserId === $hiddenField ){
$dataId[] = (int)$entrie->entry_id;
}
}
// Format Post Data into an array to make easier on html
foreach($dataId as $entry_id){
$entry = Forminator_API::get_entry( $form_id, $entry_id );
// Adding all together
$submitedData[] = [
'name' => $entry->meta_data['name-1']['value'],
];
}
?>
<?php
// Rendering on front end
foreach($submitedData as $data): ?>
<section>
<div>
<p>Username: <?php echo $data['name']; ?></p>
</div>
</section>
<?php endforeach; ?>
<?php
return ob_get_clean();
}add_shortcode('my_test_page','wpmu_order_status_876');
@patrickfreitasdev
Copy link
Author

Hi @kamaleyat-store The code is still valid, but note this will only works if you have a hidden field saving the user ID https://gist.github.com/patrickfreitasdev/3ad0d0f4e13d3618cf8be210e8a48ac5#file-forminator-front-end-data-php-L22 otherwise there is no way to know the form is submitted by that specific user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment