Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • Login
  • Get Formidable Forms

Show Field Totals and Form Statistics

Last Updated: November 11, 2021

Knowledge Base → Entries → Reports, Graphs, and Statistics → Show Field Totals and Form Statistics

— Premium Feature —

Use this shortcode to display field totals and form statistics in a page, post, View, or anywhere else shortcodes are accepted.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

Usage

Insert the following shortcode on a page, post, View, or in any field in your form.

[frm-stats id=x type=count]

Replace x with the ID or key of the field you would like to display statistics for
Replace count with the type of statistics to display (all the different types are listed below)

Required Parameters

  • id - ID or key of the field you would like to display statistics for
  • type - Specify the type of statistic you would like returned. If not specified, this defaults to total.
    • total: Adds up all the numeric values
    • count: Counts the number of entries
    • average or mean: Displays the average of numeric values
    • median: Displays the median of numeric values
    • star: Displays the average value in the format of a star rating graphic
    • maximum: Gets the maximum value from a set of values
    • minimum: Gets the minimum value from a set of values
    • unique: Counts the number of unique entries
    • deviation: Displays the standard deviation of numeric values

Optional Parameters

  • user_id

    Include only entries from a specific user in the form statistic. This must be an integer or 'current'. To get a user ID integer, go into Users, select a user, and the user ID number will be in the address bar. Example: [frm-stats id=x type=count user_id=current]

  • entry

    Get a total for a specific entry or entries. You may use entry IDs or keys. Example: [frm-stats id=x type=star entry="250,252,255"]. In a View you can use [frm-stats id=x type=star entry="[id]"]

  • parent_id

    Get a stat for a single parent entry of a field inside a repeater field. The parent_id should be the entry id or key of the entry in the main form. The field (x) should be a field in a Repeater. Example in a view: [frm-stats id=x type=total parent_id="[id]"]

  • limit

    Set a maximum number of entries to use for this stat. Example: [frm-stats id=x type=count limit=5]

  • thousands_sep

    Set the thousands separator for the displayed total. Example: [frm-stats id=x type=count thousands_sep=","]

  • decimal

    Determine the maximum number of decimal places to show. This option doesn't add trailing zeros. Example: [frm-stats id=x type=total decimal=2]

  • dec_point

    Determine which character should be used as the decimal point in the displayed number. By default, this will be a period. Example: [frm-stats id=x type=total dec_point=","]

  • drafts

    By default, the frm-stats shortcode does not count draft entries. You can choose to include only drafts, or both drafts and entries. This shortcode will count only drafts in the statistic:

    [frm-stats id=x drafts=1]

    This shortcode will count both drafts and completed entries in the statistic:

    [frm-stats id=x drafts=both]
  • parent_id

    You can get stats about the Repeaters of a particular parent entry using the parent_id param. Set parent_id to the id or key of the parent entry, and use a field in the Repeater for the stats. The parent_id param is especially useful in a View of the parent, where you can set parent_id to [id].

    [frm-stats id="x" type="total" parent_id="120"]

    In a View:

    [frm-stats id="x" type="total" parent_id="[id]"]
  • created_at_greater_than

    Only include entries created after a specific or dynamic date. For example, you may total entries created in the last month with created_at_greater_than="-1 month" or use a specific date like created_at_greater_than="2016-07-31". When using a specific date, it must be in the Y-m-d format.

    [frm-stats id="x" type="total" created_at_greater_than="Y-m-d"]
  • created_at_less_than

    Only include entries created before a specific or dynamic date. For example, you may total entries created before today with created_at_less_than="-1 day" or use a specific date like created_at_less_than="2016-05-31". When using a specific date, it must be in the Y-m-d format.

    [frm-stats id="x" type="total" created_at_less_than="-1 month"]
  • filter by a field

    Filter your form statistic by another field's value. Review the filtering options below.

Field filters

Only include entries where a field in the same form is equal to, not equal to, greater than (or equal to), less than (or equal to), or contains a specific value.

Note: you can use multiple field filters in the same shortcode to get more refined statistics. However, you can't use the exact same filter twice in the same stat. So you could have 50_greater_than=10 and 50_less_than=20 in the same stat, but not 50="silver" and 50="gold".

If a field has separate values, the field filter will use the saved value.

  • Equals

    Only include entries where a field is equal to a specific value. For example, you may get a total for field x when field 25 equals "Yes":

    [frm-stats id=x type=total 25="Yes"]

    Replace 25 with the ID of any field in the form. Replace "Yes" with any value.

  • Not equal

    Only include entries where a field is NOT equal to a specific value.

    [frm-stats id=x type=total 25_not_equal="Yes"]

    Replace 25 with the ID of any field in the form. Replace "Yes" with any value.

  • Greater than

    Only include entries where a field is greater than a specific value. This works well with numbers:

    [frm-stats id=x type=total 25_greater_than="10"]

    and also with dates:

    [frm-stats id=x type=total 25_greater_than="2015-03-01"]

    You may also use a dynamic date string:

    [frm-stats id=x type=total 25_greater_than="-1 week"]

    Replace 25 with the ID of a field in the form.

  • Greater than or equal to

    Only include entries where a field is greater than or equal to a specific value. This works well with numbers:

    [frm-stats id=x type=total 25_greater_than_or_equal_to="10"]

    and also with dates:

    [frm-stats id=x type=total 25_greater_than_or_equal_to="2015-03-01"]

    You may also use a dynamic date string:

    [frm-stats id=x type=total 25_greater_than_or_equal_to="-1 week"]

    Replace 25 with the ID of a field in the form.

  • Less than

    Only include entries where a field is less than a specific value. This works well with numbers:

    [frm-stats id=x type=total 25_less_than="10"]

    and also with dates:

    [frm-stats id=x type=total 25_less_than="2015-03-01"]

    You may also use a dynamic date string:

    [frm-stats id=x type=total 25_less_than="NOW"]

    Replace 25 with the ID of a field in the form.

  • Less than or equal to

    Only include entries where a field is less than or equal to a specific value. This works well with numbers:

    [frm-stats id=x type=total 25_less_than_or_equal_to="10"]

    and also with dates:

    [frm-stats id=x type=total 25_less_than_or_equal_to="2015-03-01"]

    You may also use a dynamic date string:

    [frm-stats id=x type=total 25_less_than_or_equal_to="NOW"]

    Replace 25 with the ID of a field in the form.

  • Contains

    Only include entries where a field contains a substring or value.

    [frm-stats id=x type=total 25_contains="Activity"]

    Replace 25 with the ID of any field in the form. Replace "Activity" with any value.

  • Does not contain

    Total entries where a field does NOT contain a substring or value.

    [frm-stats id=x type=total 25_does_not_contain="Activity"]

    Replace 25 with the ID of any field in the form. Replace "Activity" with any value.

  • Dynamic values

    To filter stats based on a parameter, use [get param="param_name"] as a dynamic value in your field filter.

    [frm-stats id=x type=total 25_greater_than="[get param=param_name]"]

    Replace 25 with the ID of any field in the form. Replace param_name with your parameter name.

Conditional stats

Use the frm-condition shortcode to conditionally show something based on the value.

Limitations

Currently, stats can only be filtered by fields in the same form. This means that stats for Repeaters can't be filtered by fields in their parent entries. Similarly, stats for parent entries can't be filtered by fields in their Repeaters.

PHP Alternative

echo FrmProStatisticsController::stats_shortcode(array('id' => x, 'type' => 'count', 'user_id' => 'current'));

All of the parameters listed above can be used in this function as well.

Related Customizations

Total entry count across all forms

This shortcode will get the total entry count across all forms for the current user. Add this function to your theme functions.php or to a new plugin, and add the shortcode [entry-count] in your page.

add_shortcode('entry-count','my_entry_count');
function my_entry_count($atts){
    global $user_ID;
    $ids = FrmDb::get_col( 'frm_items', array('user_id' => $user_ID));
    return count($ids);
}

 

Combined total for two fields

This creates a new shortcode [fields-stats] for use on your page. Your shortcode will look like this: [fields-stats ids="x,y,z"]. Replace x, y, and z with the IDs of the fields you want to total.

add_shortcode('fields-stats','my_fields_stats');
function my_fields_stats($atts){
    $defaults = array(
      'ids' => false,
    );
    $atts = array_merge($defaults, $atts);
    $ids = explode( ',', $atts['ids'] );
    unset( $atts['ids'] );

    $total = 0;
    foreach ( $ids as $id ) {
      $atts['id'] = $id;
      $total += FrmProStatisticsController::stats_shortcode( $atts );
    }
    return $total;
}

 

Subtract one simple stat from another

This creates a new shortcode that allows you to subtract one stat from the other. The stats need to be the same type (e.g. total or count) and not have any filters or use any other parameters that would be specific to one stat but not the other.
Usage: [subtract-fields total=358 removed=359 type=total].
Replace 358 with the id of the field that holds the initial total and 359 with the id of the field that holds the amount being subtracted from the total.

add_shortcode('subtract-fields','frm_subtract_fields');
function frm_subtract_fields ($atts){
    $defaults = array(
        'total' => false,
        'removed'=> false,
    );
    $atts = array_merge($defaults, $atts);
                       
    $total_id = $atts['total'];
    unset ($atts['total']);
    $removed_id = $atts['removed'];;
    unset ($atts['removed']);
 
    $atts['id'] = $total_id;;
    $total = FrmProStatisticsController::stats_shortcode( $atts );
    $atts['id'] = $removed_id;
    $removed = FrmProStatisticsController::stats_shortcode( $atts );
 
    return $total - $removed;
}

 

Percentage of a specific field value

After inserting this function in a new plugin or in your theme functions.php, add the shortcode [frm-percent id=x value="Option 1"] on your page.

add_shortcode('frm-percent', 'frm_stats_percent');
function frm_stats_percent($atts){
    $defaults = array(
    'id' => false, 'user_id' => false,
    'value' => false, 'round' => 100, 'limit' => ''
    );
    extract(shortcode_atts($defaults, $atts));
    if (!$id) return;
    $type = 'count';
    $value_count = FrmProStatisticsController::stats_shortcode(compact('id', 'type', 'value', 'limit'));
    $total_count = FrmProStatisticsController::stats_shortcode(compact('id', 'type', 'limit'));
    return round((($value_count / $total_count) * 100), $round);
}

Create a custom shortcode: simple remaining places

Sometimes, it makes sense to create your own customized shortcode to retrieve a specific value you want. In this example, the number of spaces remaining at an event is calculated using the stats shortcode. You can use [remaining] to display this number wherever you like on your site.

add_shortcode( 'remaining', 'ff_simple_remaining_places' );
function ff_simple_remaining_places( $atts ) {
    $places_taken     = FrmProStatisticsController::stats_shortcode( array(
        'id'   => 361,
        'type' => 'count'
    ) );//change 361 to the id of the field you want to count
    $remaining_places = 15 - $places_taken;//change 15 to the total number of spaces at the event
 
    return $remaining_places;
}

Replace 361 with the id of the field you want to count. Replace 15 with the total spaces for the event. Note: if you like, you can replace "count" with "total" if more than one person can sign up for the event on one form.

  • Usage
  • Required Parameters
  • Optional Parameters
    • user_id
    • entry
    • parent_id
    • limit
    • thousands_sep
    • decimal
    • dec_point
    • drafts
    • parent_id
    • created_at_greater_than
    • created_at_less_than
    • filter by a field
  • Field filters
    • Equals
    • Not equal
    • Greater than
    • Greater than or equal to
    • Less than
    • Less than or equal to
    • Contains
    • Does not contain
    • Dynamic values
  • Conditional stats
  • Limitations
  • PHP Alternative
  • Related Customizations
    • Total entry count across all forms
    • Combined total for two fields
    • Subtract one simple stat from another
    • Percentage of a specific field value
    • Create a custom shortcode: simple remaining places
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form. Maybe you need to log in?

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started See User Reviews