PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Display entries count on site.

  1. I'm using the form to collect entries for a petition. I would like to display the entry count on the site as an indicator of the progress toward our signature goal number. I'm assuming I need to do a custom SQL query to get this number, is that true or is there a function I can call. If a custom query, what would it be?

    Posted 11 years ago on Tuesday March 9, 2010 | Permalink
  2. Well, I figured out two ways, one is a custom SQL query, the other a call to the internal class RGFormsModel:

    Option 1:

    global $wpdb;
    $summary = $wpdb->get_results("SELECT COUNT(*) FROM wp_rg_lead WHERE form_id = 2");
    echo "The Form count for Form #2 is: $summary.";

    Option 2:

    $summary = RGFormsModel::get_form_counts(2);
    echo "The Form count for Form #2 is: ".$summary['total'].".";

    They both work. Anyone have an opinion on whether either (or both) of these methods is flawed in some way that I haven't realized? Or have an opinion on which approach is better or faster?

    Oh, I should point out that the "2" in both "form_id = 2" and "get_form_counts(2)" is the form id from the first column of the "Edit Forms" page in the Gravity Forms admin area.

    Posted 11 years ago on Wednesday March 10, 2010 | Permalink
  3. Option 2 is preferred since we will ensure backwards compatibility of those public functions in future releases

    Posted 11 years ago on Wednesday March 10, 2010 | Permalink
  4. Ah, perfect, then that's what I'll use. Thank you. As a side comment, is there some kind of documentation of all the available public functions within Gravity Forms?

    Posted 11 years ago on Thursday March 11, 2010 | Permalink
  5. The only true public function is the function to display a form which is documented. We haven't documented the functions the plugin itself uses, and this is actually an admin related function that we didn't design to be used on the front end.

    Posted 11 years ago on Thursday March 11, 2010 | Permalink
  6. Darrylmit
    Member

    Thanks for this thread. I too am setting up a petition wp site. I would like to use option 2, as suggested. So, my "newbie" question: Where do I past the code snippet? and, Do I need to do anything else?
    Thanks!

    Posted 11 years ago on Thursday August 12, 2010 | Permalink
  7. The code snippet would go wherever you want the entry count to be displayed. However, this is PHP so it can't go in Post or Page content. So it would have to go in your theme file. With it being PHP you would have to wrap it in PHP tags so your theme template file knows that it is PHP and not HTML.

    For example:

    <?php
    $summary = RGFormsModel::get_form_counts(2);
    echo "The Form count for Form #2 is: ".$summary['total'].".";
    ?>
    Posted 11 years ago on Thursday August 12, 2010 | Permalink
  8. Darrylmit
    Member

    Thanks. I'll try.

    Posted 11 years ago on Thursday August 12, 2010 | Permalink
  9. This may be a newbie question too - but I've searched around and couldn't find an answer!

    I'm adding this feature into a template but need to make it more generic - so instead of using a specific form id, I need to use the form id of the "current" form (if one exists). Is that possible? Happy for it to only be possible inside the loop if that's essential.

    Posted 10 years ago on Thursday November 18, 2010 | Permalink
  10. It would have to have the form id passed to it. Otherwise it won't know what form to display. Even if it's in the loop, the loop wouldn't know what form id should be passed. When a form is displayed in the loop the form id is hardcoded and not available outside of the shortcode or function call being used to display it.

    Posted 10 years ago on Thursday November 18, 2010 | Permalink
  11. Ah OK - so perhaps I need to approach a slightly different way. The aim is for the user to be able to create petition campaigns, using GF to collect email signatories. What I'd like to do is have a custom field which is the "sign-up" target (i.e. the number of signatories they'd like to reach), and I'd like to pull the current number of signups out of the form in the current post/page.

    So one way I could do that would be to create another custom field to pass the form id into the template - it's duplicate data entry but at least that would work, but is there a better way?

    Thanks for your help!

    Posted 10 years ago on Thursday November 18, 2010 | Permalink
  12. beclo
    Member

    Hi - thanks for this

    I was trying to style the output, but can't seem to get it right

    Are you able to see what is wrong with this?

    $summary = RGFormsModel::get_form_counts(1);
    echo ?><div class="counter"><?php "The Form count for Form #2 is: ".$summary['total']."."; ?> </div>

    Cheers

    Ben

    Posted 10 years ago on Saturday June 11, 2011 | Permalink
  13. Something like this is probably what you're looking for:

    http://pastie.org/2051574

    Posted 10 years ago on Saturday June 11, 2011 | Permalink
  14. beclo
    Member

    Awesome - works a treat

    Thanks very much!

    Posted 10 years ago on Saturday June 11, 2011 | Permalink
  15. websitedesignercharlotte
    Member

    I would like to do this for a fish log but I need to total entries from one numeric field on one form and echo the total. Example user one submits 10 fish through the form and creates an entry. User two submits 15 fish. How can I query all entries and get a sum of the entries from field fish caught.
    http://www.myfish.com/enter-a-fishing-trip-log/

    [details removed]

    notice sidebar widget. See my forum post for the crazy way I went about getting it to total.
    http://www.gravityhelp.com/forums/topic/totaling-all-entries-from-a-specific-field-as-a-counter#post-41547

    Posted 9 years ago on Friday November 18, 2011 | Permalink
  16. Charlotte, I'm going to close this and we will address your issue in the other topic. Thank you.

    Posted 9 years ago on Saturday November 19, 2011 | Permalink

This topic has been resolved and has been closed to new replies.