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.

Limit entries showing wrong remaining number

  1. Hi i enclosed the following code within Functions.php:

    [php]
    // http://www.gravityhelp.com/forums/topic/display-number-of-form-entries-left-per-form
    // change 3 here to your form ID
    add_filter('gform_pre_render', 'show_entries_left');
    function show_entries_left($form) {
        // get the number of entries for this form
        $entry_count = RGFormsModel::get_lead_count($form['id'], "", null, null, null, null);
    
        // subtract the entry count from the limit to determine how many are left
        $left =  $form['limitEntriesCount'] - $entry_count;
    
        // append the number of entries left to the description displayed before the form
        $form['description'] .= "Hurry! Only <strong>$left</strong> more entries will be accepted.";
    
        // return the form
        return $form;

    However the figure it is showing for a 32 team entry is 21! I have no entries in there at the moment (as i deleted them) and if i set the limit entry to "off" it shows -11 remaining. It almost appears that the figure is being pulled from somewhere else. I have entered and deleted previous entries to ensure that if data forms and entries are lost it can be re-imported again via the backup of the tables and ftp. Any ideas as to why this is happening please? The code is set to show on all tables as a counter for all entries within those forms. website link:

    http://www.primarysolutions.org/testreg

    Posted 8 years ago on Wednesday November 7, 2012 | Permalink
  2. I would echo $form['limitEntriesCount'] and $entry_count to see what they contain.

    Also, are the entries still in the trash? I think that code snippet was written before the trash functionality existed and maybe those entries are still being counted.

    If you have database access, can you check to be sure there are no leads for this form in the _rg_leads table?

    David Smith has also written a couple of articles on other ways of accomplishing the same thing:
    http://gravitywiz.com/2012/09/19/shortcode-display-number-of-entries-left/

    Maybe one of his approaches will work better for you.

    Posted 8 years ago on Thursday November 8, 2012 | Permalink
  3. YIPPERS! I learned something new today. I cleaned out the _rg_leads table and it worked!

    Is there a fix other than you've mentioned planned for this?

    Awesome thanks..........

    Posted 8 years ago on Friday November 9, 2012 | Permalink
  4. I'm not sure I understand your last question. Can you please rephrase it. Thank you.

    Posted 8 years ago on Friday November 9, 2012 | Permalink
  5. will future releases avoid the data being left in the _rg_leads file when deleted?

    Posted 8 years ago on Friday November 9, 2012 | Permalink
  6. David Peralty

    I will send a note to the development team about this to make sure it is on the list or if for some reason it is working that way on purpose, to leave a reason why. All my best!

    Posted 8 years ago on Friday November 9, 2012 | Permalink
  7. When the entry is trashed, it remains in the rg_leads table with a status of "trash". In those previous code examples, if you have an entry in the trash, it would still be counted as a submitted entry. You could modify the code to account for trash status, and not count those, or just delete your test entries permanently from the trash.

    Once you click "delete permanently" (while viewing a trashed entry) it's deleted from the database permanently. If that is not happening for you, it's possible you had caching turned on at some point? Or you may have a theme or plugin conflict.

    To summarize: a trashed entry is still in the rg_leads table, with a status of trashed, so those code examples probably still counted it as a lead. Delete the entry from the trash, and the code will be fine, or modify the code to account for entries which might have a status of "trash".

    Posted 8 years ago on Friday November 9, 2012 | Permalink
  8. "or modify the code to account for entries which might have a status of "trash".

    Don't suppose you could help a wordpress/php newb with that could you please?

    Posted 8 years ago on Tuesday November 20, 2012 | Permalink
  9. In the code of your first post, change line 6 to this to exclude trashed entries.

    [php]
    // parameters for reference:
    // get_lead_count($form_id, $search, $star=null, $read=null, $start_date=null, $end_date=null, $status=null, $payment_status = null)
    $entry_count = RGFormsModel::get_lead_count($form['id'], '', null, null, null, null, 'active', null);

    The addition of "active" as the 7th parameter there should exclude entries which are in the trash.

    Posted 8 years ago on Tuesday November 20, 2012 | Permalink
  10. Thank you so much for your help (especially the last piece Chris to not count trash items). My forms are now complete after many hours of development and work great

    Regards

    Al

    Posted 8 years ago on Wednesday March 27, 2013 | Permalink
  11. You're welcome. I'm glad that's working for you.

    Posted 8 years ago on Sunday March 31, 2013 | Permalink

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