Create Top 10 List on Detailed View

By: Fabian Pontén | Asked: 05/08/2023
ForumsCategory: How-toCreate Top 10 List on Detailed View
Fabian PonténFabian Pontén asked 11 months ago
Hi FF Communitiy!

I have 36 Hidden Fields that make a number of calculations based on the user's entry. I would like to sort these 36 fields from the highest values and show a "top 10" list on a View Details page.

Got a suggestion from the FF AI, it looks like this makes sense but I'm not sure how to display the 10 Hidden Fields on the Details page? Would really appreciate any input if any of you guys/gals know the best way to do this!

Thanks a bunch!

One approach is to use a webhook to sort the 36 fields and POST the top 10 values to a new set of fields. You can use the `frm_after_create_entry` hook to trigger the webhook after a new entry is created. In the webhook, you can use PHP to sort the fields by value and then loop through the sorted fields to get the top 10 values. You can then use the `frm_entry_update` function to update the new set of fields with the top 10 values. Here's an example code snippet to get you started:

add_action( 'frm_after_create_entry', 'sort_and_post_top_10_fields', 30, 2 ); function sort_and_post_top_10_fields( $entry_id, $form_id ) {

// Get all the field values for the entry $entry = FrmEntry::getOne( $entry_id ); $field_values = $entry->metas;

// Sort the fields by value arsort( $field_values );

// Get the top 10 fields $top_10_fields = array_slice( $field_values, 0, 10 );

// Update the new set of fields with the top 10 values foreach ( $top_10_fields as $field_id => $field_value ) {

// Replace "field_key" with the key of the new set of fields $field_key = 'field_key_' . $field_id; $field = FrmField::getOne( $field_key ); FrmEntryMeta::add( $entry_id, $field->id, $field_value ); } }
1 Answers
Rob LeVineRob LeVine answered 11 months ago
One way to do it is to have some/all over the detail page's contents be a custom shortcode in which you can do whatever you want.
Fabian PonténFabian Pontén replied 11 months ago

Hi Rob! Thanks for your answer – this seems like a possible solution. How would I apply the code into the shortcode though and achieve what I'm trying to achieve? Not too familiar with PHP unfortunately, any help is appreciated greatly 🙏

Rob LeVineRob LeVine replied 11 months ago

Hi - unfortunately, it's not something that can be explained in a forum post. It's either something that you learn by trial and error with various Formidable function calls in PHP or you can reach out to a developer, such as the list on the Formidable Masterminds list -

Fabian PonténFabian Pontén replied 11 months ago

Ah ok got it, thanks Rob, have a great day!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community