Last active
March 9, 2024 02:27
-
-
Save patrickfreitasdev/3ad0d0f4e13d3618cf8be210e8a48ac5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
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
Hello,
I am trying different ways to show submissions to users on front end, but your code above shows nothing on screen, just a white space. I also tried this one https://gist.github.com/patrickfreitasdev/9c8cab2e3309210fc83ba41dde63c075 , I got a table with data on front end but it's not for the logged in user.
please advise if the code above still valid, or I should make modifications, thank you in advance.