[cfdb-count]

October 18th, 2014

This documentation applies to version 2.6 and later

Summary of Shortcode Options

Option Example
Description
form [cfdb-count form="myform"] Required. Designates the form to display. All rows and columns are displayed by default
role [cfdb-datatable form="myform" role="Author"] Make short code only display output for user’s with minimum-required role. Choices are

  • Administrator
  • Editor
  • Author
  • Contributor
  • Subscriber
  • Anyone

WARNING: this setting is overridden by plugin setting in WP Admin page Contact -> Database Options -> Can See Submission when using shortcodes
(since 2.4.1)

show [cfdb-count form="myform" show="col1,col2"] **Not applicable to this shortcode
hide [cfdb-count form="myform" hide="col1,col2"] **Not applicable to this shortcode
limit [cfdb-count form="myform" limit="10"] ** Applicable only if you would want to limit the count to a maximum number.
orderby [cfdb-count form="myform" orderby="last-name,first-name"] **Not applicable to this shortcode
search [cfdb-count form="myform" search="Simpson"] Select rows to display that have any cell with the search text in it (case insensitive). Intended to mimic behavior of the “Search” field in the DataTable
filter [cfdb-count form="myform" filter="col1=Simpson"] Select which rows to display based on filter expression. More powerful than “search”, it can filter on multiple columns with boolean and regular expressions. If both “search” and “filter” are specified, “search” is ignored.


Example: Want to simply count of the number of form entries received? Maybe you want to show how many people have signed your on-line petition?

[cfdb-count form="your-form"]

Example: Want to show vote counts?

Yes Votes: [cfdb-count form="your-form" filter="vote=yes"]

No Votes:  [cfdb-count form="your-form" filter="vote=no"]

 

The same thing can be accomplished with the [cfdb-value] shortcode, this shortcode is really just an abbreviation.
So:

[cfdb-count form="your-form"]

Is equivalent to:

[cfdb-value form="your-form" function="count"]

But there is a subtle difference with cfdb-value. With that shortcode, if you use any other function rather than "count" (like "sum" or "max") then you need to specify the column or columns that will be applied. Otherwise it will try to compute across all columns. So if you used "count" and specified two columns, you get the number of entries submitted times two. Not a useful example, but if you were using "mean" it would be.

 

  1. shane
    February 23rd, 2012 at 07:58 | #1

    I want to programatically access cfdb-count.
    Would you teach me php code, please.

  2. Shaun
    February 29th, 2012 at 04:58 | #2

    shane :
    I want to programatically access cfdb-count.
    Would you teach me php code, please.

    I also need this bit of code. Any chance you could post a hint please? Many thanks

  3. Michael Simpson
    March 3rd, 2012 at 17:06 | #3

    @Shaun
    include_once(ABSPATH . ‘wp-content/plugins/contact-form-7-to-database-extension/CFDBShortcodeCount.php’);
    $countShortCode = new CFDBShortcodeCount();
    $attributes = array(‘form’ => ‘Contact form 1′);
    echo($countShortCode->handleShortCode($attributes));

  4. Shaun
    March 6th, 2012 at 08:59 | #4

    Thanks Michael. I managed to get it goingin my WordPress template using this bit of PHP:
    do_shortcode( ‘[contact-form-7 id="XXX" title="Form title"]‘ );
    Cheers

  5. April 17th, 2012 at 07:01 | #5

    hello! I am trying to show with the count code [cfdb-value form="your-form" function="count"] the number of people registered from the form on the page. It works wonderful in safari and firefox, but not in Explorer, could you please help me? thank you very much.

    the web is this one: http://www.procattic.cat/ the form is the one in the right column that says: Ja som xxx professionals inscrits!

    thank oyu very much!!

    • Michael Simpson
      April 18th, 2012 at 09:36 | #6

      I looked at the page and I can see the “Ja som 13 professionals inscrits!” using IE9 on Windows 7. Underlying HTML is
      <p style=”font: 10pt Arial Black;color:#EC1C24;”>Ja som 13 professionals inscrits!</p>

  6. April 17th, 2012 at 07:21 | #7

    @Michael Simpson

    How can I include this code into the widget?
    my widget code looks like this now:

    Ja som [cfdb-value form="Contact form 1" function="count"] professionals inscrits!

    and as I wrote before, explorer can not see the count value…
    thank you very much!

  7. April 18th, 2012 at 11:53 | #8

    yes! thank you for replying! i put the code plus the function= and worked! I just did not have any pc to see it. thank you very much for the reply!

  8. Pxl
    June 20th, 2012 at 07:18 | #9

    Hi!

    Thanks for a great plugin. How would I in the simplest manner display the number of counted entries +1000.
    I’m working on a site where every person signing up gives a 1000 “dollars”, so I want the count function to multiply with 1000.

    Thanks in advance….

    • Michael Simpson
      June 20th, 2012 at 13:56 | #10

      Try putting that into a javascript variable and printing that out:
      <script type="text/javascript">
      var value = [cfdb-value ....] * 1000;
      document.write("$" + value);
      </script>

  9. Shin’
    June 25th, 2012 at 06:14 | #11

    When I login as admin, I can see the result. but when logout, I can see anything.
    How do I do ?

    • Michael Simpson
      June 25th, 2012 at 10:21 | #12

      You need to change a setting. Go to the Database Options page in the administration panel, set “Can See Submission when using shortcodes” to “Anyone”

  10. Peter Risman
    October 24th, 2012 at 19:08 | #13

    I am trying to create a post-submission email that pulls data from the row that was just created. I can’t figure out how to dynamically pull the most recent row of data from the table.

    What am I missing? Thanks!

    p

    • Michael Simpson
      October 24th, 2012 at 22:35 | #14

      You posted this question on the [cfdb-count] page. Obviously “count” is not going to give you the latest row. But with other short codes, get the most recent row using “limit” like [cfdb-table limit="1"]. By default the results are ordered youngest-to-oldest so if you limit to 1, you should get the most recent one.

  11. Peter Risman
    October 29th, 2012 at 09:15 | #15

    Excellent – thank you Michael!

  12. Peter
    November 17th, 2012 at 09:57 | #16

    I simply want to display the amount of submissions of a certain form, so I use [cfdb-count form="name-of-form"] (no other parameters) but the result is allways 0…
    After submitting a form it does add all the information to a row in the db.
    I also checked the shortcode with the generator.
    What have I missed?
    Using version 2.4.3 with CF7 version 3.3.1 on WP version 3.4.2 (all the latest versions).
    Thnx!

  13. Peter
    November 17th, 2012 at 19:13 | #17

    @Peter
    I just found out this happened because the form name contained a comma!

  14. January 8th, 2013 at 15:07 | #18

    @Michael

    I want to count based on a compound filter. Using the Shortcode Builder gives me this but it doesn’t work:

    [cfdb-count form="Net Promoter Score_TEST" role="Anyone" permissionmsg="true" filter="PracticeName=AAN&&NetPromoterScore=1&&Submitted~~/^2013-01/"]

    So I want the PracticeName = AAN, the NetPromoterScore = 1 for the month of January 2013 which is Submitted~~/^2013-01/

    Any help is much appreciated Michael. Thank you!

  15. Michael Simpson
    January 9th, 2013 at 15:40 | #19

    @Paul Podczervinski
    I think the problem is the “Submitted”. Try using “submit_time” instead.

  16. January 9th, 2013 at 15:45 | #20

    @Michael Simpson

    @Michael Simpson

    Thanks Michael! What would be your suggestion if I want all data for the month of January 2013?

  17. Michael Simpson
    January 9th, 2013 at 15:51 | #21

    @Paul Podczervinski
    submit_time>=1/1/2013&&submit_time<=2/1/2013

  18. January 9th, 2013 at 15:59 | #22

    @Michael Simpson

    My thought was:

    [cfdb-count form="Net Promoter Score_TEST" role="Anyone" permissionmsg="true" filter="PracticeName=AAN&&NetPromoterScore=10&&submit_time>January 1, 2013&&submit_timeJanuary 1, 2013||submit_time<=January 31, 2013"]

    and that didn't work either.

  19. Michael Simpson
    January 9th, 2013 at 16:09 | #23

    You are missing an operator in “submit_timeJanuary 1, 2013″ like “submit_time>=January 1, 2013
    Note that all the && are evaluated first then the ||. Based on what you have, it would get results that match your first bunch of constrains plus everything that only matches submit_time< =January 31, 2013

    Try building up the filter piece by piece in the short code builder page, checking the results at each step.

    I think you want
    [cfdb-count form="Net Promoter Score_TEST" role="Anyone" permissionmsg="true" filter="PracticeName=AAN&&NetPromoterScore=10&&submit_time>=January 1, 2013&&submit_time<=January 31, 2013″]

  20. jasnon
    August 16th, 2013 at 13:49 | #24

    Hi Michael,

    Is there a way to use this shortcode to count the number of “unique” submissions in a form based on username? For example, I have a form where logged-in users can submit multiple times throughout the year but at the end of the year I want to be able to tell how many “different” users made submissions. Right now I can only get the shortcode to count the total number of submissions throughout the year but not the number of unique users who made submissions.

    Thanks,
    Jon

  21. mikeshaker
    March 29th, 2014 at 11:35 | #26

    Hi Michael, Thanks for an awesome plugin. I have question I been trying to figure it out all day.
    I am trying Showing how many times a distinct value appears in database.
    for example if this my table. group them by name(one or two column) and count how many times it appears
    +———+—————+———+
    | Name | email | Subject |
    +———+—————+———+
    | Mike AA | test@test.com | test |
    | John | a@test.com | w |
    | Mike AA | test@test.com | zzzz |
    +———+—————+———+

    to be like this
    +———+—————+———+——-+
    | Name | email | Subject | Count |
    +———+—————+———+——-+
    | Mike AA | test@test.com | test | 2 |
    | John | a@test.com | w | 1 |
    +———+—————+———+——-+

    • Michael Simpson
      March 29th, 2014 at 14:27 | #27

      If you know ahead of time unique things you are looking for, then you can add that to “filter” to count them. But the short codes does not give you a SQL “group by” kind of capability. You would have to write your own short code to identify the unique values and count them.

  22. mikeshaker
    March 29th, 2014 at 15:55 | #28

    @Michael Simpson Thanks for your quick reply.

Comments are closed.  Go To Support Forum