Simple frm-stat count with one filter is not working

By: brett Marsh | Asked: 08/29/2024
ForumsCategory: How-toSimple frm-stat count with one filter is not working
brett Marsh asked 3 weeks ago
Hi all The following formula works well when placed in the default calc section of my field. It simply counts entries in field 98 (of a second form) where field 96 (of the second form) = “work”. [frm-stats id=98 type=count 96=work] However, I want to filter the count based on the value in field 1058 of the current form of which the value “work” is one of 4 possible values, ie: [frm-stats id=98 type=count 96=1058] However, this does not work, even if I type “work” directly into field 1058 as default.  I have tried “[1058]” and just [1058], as well as the field key.  For some reason it seems it is not replacing the field id (eg 1058) with the value sitting in that field. Any tips would be greatly appreciated. Brett
1 Answers
Victor Font answered 3 weeks ago

When you pass parameters to a shortcode, you are passing key/value pairs that are stored in the @atts array. This is how the WordPress Shortcode API works. So when you pass 96=1058 or any variation thereof, you are literally asking the shortcode to calculate a value where field 96 equals 1058. While I don't understand entirely what you want to do, your question raises curiosity in my mind about your design. If you want to count what's in the current form, why don't you just count what's in the current form? What is the second form for and why do you need to link it back to the current form? Do either of these forms serve as the single source of truth for the values you want to calculate?

brett Marsh replied 2 weeks ago

<p>Hi Victor, thanks for your reply. I’ll try to articulate a bit more clearly. I have a form (Form 1) which has 3 fields being ID = 96, 97, 98. This table has several hundred lines of externally loaded data. My second form has corresponding cascading lookup fields, being 109, 110, 111, in the form of dropdowns. However, when there are no available options for the user to select from in field 111, I don’t want that field even shown to the user. In other words, I want it hidden until the user has selected from the dropdown values of fields 109 and 110, then unhidden if 111 has any values to select from. I was planning on having a hidden field (eg field 120) that calculated the number of options in the 111 dropdown, then using conditional logic to unhide field 111 if that value was >0. But I can’t work out how to calculate the number of dropdown options in field 111. The calculation of [frm-stats id=98 type=count] successfully returns the total number of options, but doesn’t take into account the cascading/filtering. So I want to include the cascading selections as filtering options in this calculation, such as [frm-stats id=98 type=count 96=”109 selection” 97=”110 selection”]. However, I don’t know how to represent the 109 selection when using the frm-stats code. Normally I would just use [109], but it does not work in this case.</p>

brett Marsh replied 2 weeks ago

Interestingly, the following syntax, which I've used in another form, does work:
[frm-field-value field_id=1094 user_id=current 142=1098] - where fields 1094 and 142 are in another form and field 1098 is a field in the form currently being completed by the user.

However, the same syntax does not work for frm stats, ie: [frm-stats id=98 type=count 96=109] - where fields 98 and 96 are in another form and field 109 is in the current form. If I delete the 96=109, then it calculates, but without the filter.

Unless I'm missing something, there seems to be an inconsistencies between the syntax.

Victor Font replied 2 weeks ago

You shouldn't expect two different shortcodes that provide completely different functionalities to work with the same parameters. frm-field-value is used to get the value from a single field entry and display it in a page, post, View or form field. This can be particularly helpful in auto-populating forms for your users.

frm-stats is used to display field totals and form statistics in a page, post, View, or anywhere else shortcodes are accepted.

brett Marsh replied 2 weeks ago

<p>So what I'm hearing from you is that there is not a way to filter the frm-stats count function when using it in a default value calculation?</p>

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
crossarrow-right